码迷,mamicode.com
首页 > Web开发 > 详细

kubernetes云平台管理实战: 服务发现和负载均衡(五)

时间:2019-02-21 12:53:53      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:副本   name   str   namespace   default   replicat   nbsp   res   pod   

一、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

 

kubernetes云平台管理实战: 服务发现和负载均衡(五)

标签:副本   name   str   namespace   default   replicat   nbsp   res   pod   

原文地址:https://www.cnblogs.com/luoahong/p/10299989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!