• 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
  • 相关阅读:
    数据库主从同步相关问题
    前端使用node.js的http-server开启一个本地服务器
    css中height 100vh的应用场景,动态高度百分比布局,浏览器视区大小单位
    通过浏览器F12开发工具快速获取别的网站前端代码的方法
    vue打包app嵌入h5,区分app进入和android,ios显示不同的下载链接
    vue实现验证码倒计时60秒的具体代码
    vue用hbuilderX打包app嵌入h5方式云打包和遇到的问题
    Cookie写不进去问题深入调查 https Secure Cookie
    vue配置手机通过IP访问电脑开发环境
    区块链名词解析:ICO、IFO、IEO和IMO,分别是什么呢?
  • 原文地址:https://www.cnblogs.com/luoahong/p/10299989.html
Copyright © 2020-2023  润新知