标签:images asc article cal div style meta root view
kubernetes实战-基于redis和docker的留言簿案例
版权声明:本文为博主原创文章,未经博主允许不得转载。
[root@centos1 example]# kubectl create -f redis-master-controller.json
replicationcontrollers/redis-master
[root@centos1 example]# kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
redis-master master redis name=redis-master 1
[root@centos1 example]# kubectl get pods
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running 55 seconds
master redis Running 55 seconds
[root@centos2 yum.repos.d]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
91689ce56668 redis:latest "/entrypoint.sh redi 3 minutes ago Up 3 minutes k8s_master.52732b08_redis-master-svar7_default_5b6d5485-1894-11e5-b3ad-000c293c8c19_97e79b7b
38c3180813c3 gcr.io/google_containers/pause:0.8.0 "/pause" 3 minutes ago Up 3 minutes k8s_POD.49eee8c2_redis-master-svar7_default_5b6d5485-1894-11e5-b3ad-000c293c8c19_298e038f
[root@centos1 example]# kubectl create -f redis-master-service.json
services/redis-master
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
[root@centos1 example]# kubectl create -f redis-slave-controller.json
replicationcontrollers/redis-slave
[root@centos1 example]# kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
redis-master master redis name=redis-master 1
redis-slave slave kubernetes/redis-slave:v2 name=redis-slave 2
[root@centos1 example]# kubectl get pods
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running 41 minutes
master redis Running 41 minutes
redis-slave-31tkb 172.17.0.10 centos2/192.168.1.112 name=redis-slave Running 29 seconds
slave kubernetes/redis-slave:v2 Running 28 seconds
redis-slave-uk8nu 172.17.0.11 centos2/192.168.1.112 name=redis-slave Running 29 seconds
slave kubernetes/redis-slave:v2 Running 28 seconds
[root@centos1 example]# kubectl create -f redis-slave-service.json
services/redis-slave
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
[root@centos1 example]# kubectl create -f frontend-controller.json
replicationcontrollers/frontend
[root@centos1 example]# kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
frontend php-redis kubernetes/example-guestbook-php-redis:v2 name=frontend 3
redis-master master redis name=redis-master 1
redis-slave slave kubernetes/redis-slave:v2 name=redis-slave 2
[root@centos1 example]# kubectl get pods
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
frontend-fr5z1 172.17.0.13 centos2/192.168.1.112 name=frontend Running 2 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 2 minutes
frontend-gjx3t 172.17.0.14 centos2/192.168.1.112 name=frontend Running 2 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 2 minutes
frontend-v608r 172.17.0.12 centos2/192.168.1.112 name=frontend Running 2 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 2 minutes
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running 53 minutes
master redis Running 53 minutes
redis-slave-31tkb 172.17.0.10 centos2/192.168.1.112 name=redis-slave Running 12 minutes
slave kubernetes/redis-slave:v2 Running 12 minutes
redis-slave-uk8nu 172.17.0.11 centos2/192.168.1.112 name=redis-slave Running 12 minutes
slave kubernetes/redis-slave:v2 Running 12 minutes
[root@centos1 example]# kubectl create -f frontend-service.json
services/frontend
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
frontend name=frontend name=frontend 10.254.154.111 80/TCP
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
NodePort
s 和LoadBalancer
s,https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/services.md#external-services[root@centos1 example]# kubectl get pods,services
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
frontend-fr5z1 172.17.0.13 centos2/192.168.1.112 name=frontend Running 22 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 22 minutes
frontend-gjx3t 172.17.0.14 centos2/192.168.1.112 name=frontend Running 22 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 22 minutes
frontend-v608r 172.17.0.12 centos2/192.168.1.112 name=frontend Running 22 minutes
php-redis kubernetes/example-guestbook-php-redis:v2 Running 22 minutes
redis-master-svar7 172.17.0.9 centos2/192.168.1.112 name=redis-master Running About an hour
master redis Running About an hour
redis-slave-31tkb 172.17.0.10 centos2/192.168.1.112 name=redis-slave Running 32 minutes
slave kubernetes/redis-slave:v2 Running 32 minutes
redis-slave-uk8nu 172.17.0.11 centos2/192.168.1.112 name=redis-slave Running 32 minutes
slave kubernetes/redis-slave:v2 Running 32 minutes
NAME LABELS SELECTOR IP(S) PORT(S)
frontend name=frontend name=frontend 10.254.154.111 80/TCP
kubernetes component=apiserver,provider=kubernetes <none> 10.254.0.2 443/TCP
kubernetes-ro component=apiserver,provider=kubernetes <none> 10.254.0.1 80/TCP
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
[root@centos1 example]# kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
frontend name=frontend name=frontend 10.254.154.111 80/TCP
kubernetes component=apiserver,provider=kubernetes <none> 10.254.0.2 443/TCP
kubernetes-ro component=apiserver,provider=kubernetes <none> 10.254.0.1 80/TCP
redis-master name=redis-master name=redis-master 10.254.154.90 6379/TCP
redis-slave name=redis-slave name=redis-slave 10.254.159.145 6379/TCP
-A KUBE-PORTALS-HOST -d 10.254.154.90/32 -p tcp -m comment --comment "default/redis-master:" -m tcp --dport 6379 -j DNAT --to-destination 192.168.1.112:49038
[root@centos2 yum.repos.d]# redis-cli -p 49038
127.0.0.1:49038> set a b
OK
127.0.0.1:49038> get a
"b"
curl "localhost:8000/index.php?cmd=set&key=messages&value=jay_sais_hi"
curl "localhost:8000/index.php?cmd=get&key=messages"
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"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":"redis",
"ports":[
{
"containerPort":6379
}
]
}
]
}
}
}
}
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"redis-master",
"labels":{
"name":"redis-master"
}
},
"spec":{
"ports": [
{
"port":6379,
"targetPort":6379
}
],
"selector":{
"name":"redis-master"
}
}
}
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"metadata":{
"name":"redis-slave",
"labels":{
"name":"redis-slave"
}
},
"spec":{
"replicas":2,
"selector":{
"name":"redis-slave"
},
"template":{
"metadata":{
"labels":{
"name":"redis-slave"
}
},
"spec":{
"containers":[
{
"name":"slave",
"image":"kubernetes/redis-slave:v2",
"ports":[
{
"containerPort":6379
}
]
}
]
}
}
}
}
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"redis-slave",
"labels":{
"name":"redis-slave"
}
},
"spec":{
"ports": [
{
"port":6379
}
],
"selector":{
"name":"redis-slave"
}
}
}
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"metadata":{
"name":"frontend",
"labels":{
"name":"frontend"
}
},
"spec":{
"replicas":3,
"selector":{
"name":"frontend"
},
"template":{
"metadata":{
"labels":{
"name":"frontend"
}
},
"spec":{
"containers":[
{
"name":"php-redis",
"image":"kubernetes/example-guestbook-php-redis:v2",
"ports":[
{
"containerPort":80
}
]
}
]
}
}
}
}
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"frontend",
"labels":{
"name":"frontend"
}
},
"spec":{
"ports": [
{
"port":80
}
],
"selector":{
"name":"frontend"
}
}
}
redis,docker和kubernetes留言簿案例实战
标签:images asc article cal div style meta root view
原文地址:http://www.cnblogs.com/Leo_wl/p/6098773.html