[root@SN2014-12-200 replication]# kubectl get pod
NAME IMAGE(S) HOST LABELS STATUS84150ab7-89f8-11e4-970d-000c292f1620 yorko/webserver 192.168.1.202/ name=webserver_pod Running
84154ed5-89f8-11e4-970d-000c292f1620 yorko/webserver 192.168.1.201/ name=webserver_pod Running
840beb1b-89f8-11e4-970d-000c292f1620 yorko/webserver 192.168.1.202/ name=webserver_pod Running
84152d93-89f8-11e4-970d-000c292f1620 yorko/webserver 192.168.1.202/ name=webserver_pod Running
840db120-89f8-11e4-970d-000c292f1620 yorko/webserver 192.168.1.201/ name=webserver_pod Running
8413b4f3-89f8-11e4-970d-000c292f1620 yorko/webserver 192.168.1.201/ name=webserver_pod Running
2.创建一个service,通过selector指定 "name": "webserver_pod"与pods关联。
【service/lnmp-service.json】
{"id": "webserver",
"kind": "Service",
"apiVersion": "v1beta1",
"selector": {
"name": "webserver_pod",
},
"protocol": "TCP",
"containerPort": 80,
"port": 8080
}
执行创建命令:
# kubectl create -f lnmp-service.json
登录minion主机(192.168.1.201),查询主宿机生成的iptables转发规则(最后一行)
# iptables -nvL -t nat
Chain KUBE-PROXY (2 references)pkts bytes target prot opt in out source destination
2 120 REDIRECT tcp -- * * 0.0.0.0/0 10.254.102.162 /* kubernetes */ tcp dpt:443 redir ports 47700
1 60 REDIRECT tcp -- * * 0.0.0.0/0 10.254.28.74 /* kubernetes-ro */ tcp dpt:80 redir ports 60099
0 0 REDIRECT tcp -- * * 0.0.0.0/0 10.254.216.51 /* webserver */ tcp dpt:8080 redir ports 40689
访问测试,:40689/info.php,刷新浏览器发现proxy后端的变化,默认为随机轮循算法。
三、测试过程
1.pods自动复制、销毁测试,观察Kubernetes自动保持副本数(6份)
删除replicationcontrollers中一个副本fedoraapache
[root@SN2014-12-200 pods]# kubectl delete pods fedoraapache
I1219 23:59:39.305730 9516 restclient.go:133] Waiting for completion of operation 142530
fedoraapache