首页 > 代码库 > k8s1.5.3集群测试之部署PODS实例
k8s1.5.3集群测试之部署PODS实例
k8s1.5.3集群测试之部署PODS实例
安装部署集群环境参考
http://jerrymin.blog.51cto.com/3002256/1898243
测试docker容器参考Guestbook示例
1,下载镜像
本例中使用3个Docker镜像,下载地址为https://hub.docker.com/u/kubeguide/
[root@k8s-node1 ~]# docker pull kubeguide/guestbook-php-frontend
[root@k8s-node1 ~]# docker pull kubeguide/guestbook-redis-master
[root@k8s-node1 ~]# docker pull kubeguide/guestbook-redis-slave
查看镜像
[root@k8s-node1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/kubeguide/guestbook-php-frontend latest 47ee16830e89 7 months ago 510 MB
docker.io/kubeguide/redis-master latest 405a0b586f7e 18 months ago 419.1 MB
docker.io/kubeguide/guestbook-redis-slave latest e0c36a1fa372 18 months ago 109.5 MB
2,创建redis-mastr RC和Service
例子可参考Kubernetes实践指南第二章
[root@k8s-master guestbook]# ls
frontend-rc.yaml redis-master-rc.yaml redis-slave-rc.yaml
frontend-service.yaml redis-master-service.yaml redis-slave-service.yaml
首先为redis-master创建一个RC(副本控制器)
[root@k8s-master guestbook]# cat redis-master-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-master
labels:
name: redis-master
spec:
replicas: 1
selector:
name: redis-master
template:
metadata:
labels:
name: redis-master
spec:
containers:
- name: master
image: kubeguide/redis-master
ports:
- containerPort: 6379
在master节点执行如下创建RC redis-master
[root@k8s-master guestbook]# kubectl create -f redis-master-rc.yaml
replicationcontroller "redis-master" created
[root@k8s-master guestbook]# kubectl get rc
NAME DESIRED CURRENT READY AGE
redis-master 1 1 0 8s
在master节点执行如下创建Service redis-master
[root@k8s-master guestbook]# kubectl create -f redis-master-service.yaml
service "redis-master" created
[root@k8s-master guestbook]# kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.254.0.1 <none> 443/TCP 1d
redis-master 10.254.6.192 <none> 6379/TCP 12s
[root@k8s-master guestbook]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
redis-master-qg457 1/1 Running 0 1h 10.1.8.2 k8s-node2
可以看到Pod运行在k8s-node2节点上,node间可以通过tcp 10.1.8.2的6379端口访问redis-master
查看描述信息
[root@k8s-master guestbook]# kubectl describe pods redis-master-qg457
Name: redis-master-qg457
Namespace: default
Node: k8s-node2/172.17.3.8
Start Time: Thu, 16 Feb 2017 12:45:19 +0800
Labels: name=redis-master
Status: Running
IP: 10.1.8.2
Controllers: ReplicationController/redis-master
Containers:
master:
Container ID: docker://eb2e83544f80e54c3f864f1a4a1edd062b9bb94d979137509e41673f85d90160
Image: kubeguide/redis-master
Image ID: docker-pullable://docker.io/kubeguide/redis-master@sha256:e11eae36476b02a195693689f88a325b30540f5c15adbf531caaecceb65f5b4d
Port: 6379/TCP
State: Running
Started: Thu, 16 Feb 2017 12:46:02 +0800
Ready: True
Restart Count: 0
Volume Mounts: <none>
Environment Variables: <none>
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
No volumes.
QoS Class: BestEffort
Tolerations: <none>
No events.
在k8s-node2上确认docer进程
[root@k8s-node2 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eb2e83544f80 kubeguide/redis-master "redis-server /etc/re" About an hour ago Up About an hour k8s_master.dd7e04d1_redis-master-qg457_default_b755b620-f402-11e6-b4a4-c81f66d97bc3_de6042eb
26f1ae8f360c registry.access.redhat.com/rhel7/pod-infrastructure:latest "/pod" About an hour ago Up About an hour k8s_POD.36030bb2_redis-master-qg457_default_b755b620-f402-11e6-b4a4-c81f66d97bc3_da1642b5
3,创建redis-slave RC和Service
[root@k8s-master guestbook]# kubectl create -f redis-slave-rc.yaml
replicationcontroller "redis-slave" created
[root@k8s-master guestbook]# kubectl get rc
NAME DESIRED CURRENT READY AGE
redis-master 1 1 1 3h
redis-slave 2 2 2 1m
[root@k8s-master guestbook]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
redis-master-qg457 1/1 Running 0 3h 10.1.8.2 k8s-node2
redis-slave-40tjp 1/1 Running 0 1m 10.1.8.3 k8s-node2
redis-slave-fh4mg 1/1 Running 0 1m 10.1.89.2 k8s-node1
[root@k8s-master guestbook]# kubectl create -f redis-slave-service.yaml
service "redis-slave" created
[root@k8s-master guestbook]# kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.254.0.1 <none> 443/TCP 1d
redis-master 10.254.6.192 <none> 6379/TCP 2h
redis-slave 10.254.183.118 <none> 6379/TCP 3m
查看主从状态
[root@k8s-master guestbook]# kubectl exec redis-master-qg457 redis-cli info|grep role
role:master
[root@k8s-master guestbook]# kubectl exec redis-slave-40tjp redis-cli info|grep role
role:slave
[root@k8s-master guestbook]# kubectl exec redis-slave-40tjp redis-cli info|grep master
master_host:redis-master
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
master_link_down_since_seconds:1487234901
master_repl_offset:0
进入修改hosts,由于没有kube-dns,所有slave都需要手动添加redis-master解析
[root@k8s-master guestbook]# kubectl exec -ti redis-slave-40tjp -- bash
root@redis-slave-40tjp:/data#echo ‘10.1.8.2 redis-master‘ >> /etc/hosts
4,创建frontend RC和Service
[root@k8s-master guestbook]# kubectl create -f frontend-rc.yaml
replicationcontroller "frontend" created
[root@k8s-master guestbook]# kubectl create -f frontend-service.yaml
service "frontend" created
[root@k8s-master guestbook]# kubectl get rc
NAME DESIRED CURRENT READY AGE
frontend 3 3 2 14s
redis-master 1 1 1 4h
redis-slave 2 2 2 1h
[root@k8s-master guestbook]# kubectl get pods
NAME READY STATUS RESTARTS AGE
frontend-jfz4c 1/1 Running 0 20s
frontend-lktm2 1/1 Running 0 20s
frontend-t8ctd 1/1 Running 0 20s
redis-master-qg457 1/1 Running 0 4h
redis-slave-40tjp 1/1 Running 0 1h
redis-slave-fh4mg 1/1 Running 0 1h
[root@k8s-master guestbook]# kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend 10.254.214.44 <nodes> 80:30001/TCP 2m
kubernetes 10.254.0.1 <none> 443/TCP 1d
redis-master 10.254.6.192 <none> 6379/TCP 3h
redis-slave 10.254.183.118 <none> 6379/TCP 1h
5,通过浏览器访问frontend页面
访问IP是node的IP加30001端口 ,本次测试应该是
http://172.17.3.7:30001或者http://172.17.3.8:30001目前是两个测试node
本文出自 “jerrymin” 博客,请务必保留此出处http://jerrymin.blog.51cto.com/3002256/1900260
k8s1.5.3集群测试之部署PODS实例