kubernetes云平台管理实战: 服务发现和负载均衡(五)
一、rc控制器常用命令
1、rc控制器信息查看
[root@k8s-master ~]# kubectl get replicationcontroller NAME DESIRED CURRENT READY AGE myweb 3 3 3 3m [root@k8s-master ~]# kubectl get rc NAME DESIRED CURRENT READY AGE myweb 3 3 3 5m
2、删除rc
[root@k8s-master ~]# kubectl delete rc myweb replicationcontroller "myweb" deleted [root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE nginx 1/1 Running 0 1h nginx2 1/1 Running 0 24m
二、服务发现和负载均衡
1、修改nginx2的标签名为:myweb
[root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myweb-cbt47 1/1 Running 0 4m myweb-fhfgs 1/1 Running 0 4m myweb-fltnm 1/1 Running 0 4m nginx 1/1 Running 0 1h nginx2 1/1 Running 0 30m [root@k8s-master ~]# kubectl edit pod nginx2 #app: myweb 修改nginx的标签名为:myweb pod "nginx2" edited [root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myweb-cbt47 1/1 Running 0 8m myweb-fltnm 1/1 Running 0 8m nginx 1/1 Running 0 1h nginx2 1/1 Running 0 33m
2、咋突然少了一个容器?
[root@k8s-master ~]# kubectl describe pod nginx2 #Labels: app=web Name: nginx2 Namespace: default Node: k8s-node2/10.0.128.2 Start Time: Sun, 20 Jan 2019 14:06:50 +0800 Labels: app=web Status: Running IP: 172.16.48.2 [root@k8s-master ~]# kubectl describe pod myweb-cbt47 #Labels: app=myweb Name: myweb-cbt47 Namespace: default Node: k8s-node2/10.0.128.2 Start Time: Sun, 20 Jan 2019 14:32:19 +0800 Labels: app=myweb Status: Running IP: 172.16.48.3 Controllers: ReplicationController/myweb
3、小结
1、因为控制器设置最少保持3个副本
2、rc控制器是根据Labels 来区分组别的
2、nginx2的标签和myweb控制器的标签一样,所以就删除了存活时间最短的容器
三、动态修改rc副本数量
1、修改为2
[root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myweb-cbt47 1/1 Running 0 9m myweb-fltnm 1/1 Running 0 9m nginx 1/1 Running 0 1h nginx2 1/1 Running 0 35m [root@k8s-master ~]# kubectl edit rc myweb replicas: 2 replicationcontroller "myweb" edited [root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myweb-cbt47 1/1 Running 0 11m nginx 1/1 Running 0 1h nginx2 1/1 Running 0 36m
2、修改为5
[root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myweb-cbt47 1/1 Running 0 11m nginx 1/1 Running 0 1h nginx2 1/1 Running 0 36m [root@k8s-master ~]# kubectl edit rc myweb replicas: 5 replicationcontroller "myweb" edited [root@k8s-master ~]# kubectl get pod NAME READY STATUS RESTARTS AGE myweb-7w38b 0/1 ContainerCreating 0 3s myweb-btflm 1/1 Running 0 3s myweb-cbt47 1/1 Running 0 12m myweb-rt3b9 0/1 ContainerCreating 0 3s nginx 1/1 Running 0 1h nginx2 1/1 Running 0 38m
作者:罗阿红
出处:http://www.cnblogs.com/luoahong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。