zoukankan      html  css  js  c++  java
  • Centos7 k8s Replication副本控制器

    一、k8s副本控制器

      Replication Controller (RC)是kubernetes 中的另一个核心概念,应用托管在kubernetes之后,kubernetes需要保证应用能够持续运行,这是RC的工作内容,它会确保任何时间kubernetes中都有指定数量的pod在运行。在此基础上,RC还提供了一些更高级的特性,比如滚动升级、升级回滚等。

      1、创建配置文件

    [root@k8s-master ~]# vim nginx-rc.yaml
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: nginx
    spec:
    replicas: 3
    selector:
    app: nginx
    template:
    metadata:
    labels:
    app: nginx
    spec:
    containers:
    - name: nginx
    image: 192.168.125.130:5000/nginx:1.19
    ports:
    - containerPort: 80

      2、执行副本配置文件

    [root@k8s-master ~]# kubectl create -f nginx-rc.yaml 
    replicationcontroller "nginx" created

     replicationcontroller会再起三个pod,replicationcontroller会一直监控pod,一直保持3个,死一个,起一个,多一个,就自动杀死一个pod。

    二、k8s lables标签管理

    [root@k8s-master ~]# kubectl edit rc nginx                       手动修改pod配置文件
    [root@k8s-master ~]# kubectl get all 查看所有pod,带标签

     三、升级和降级

    [root@k8s-master ~]# docker pull nginx:1.13                                                 拉取镜像
    [root@k8s-master ~]# docker tag docker.io/nginx:1.13 192.168.125.130:5000/nginx:1.13        打标签
    [root@k8s-master ~]# docker push  192.168.125.130:5000/nginx:1.13                           推送至私有仓库
    [root@k8s-master ~]# kubectl get pod
    NAME READY STATUS RESTARTS AGE
    nginx 1/1 Running 0 1h
    [root@k8s-master ~]# 
    [root@k8s-master ~]# kubectl get pod -o wide
    NAME READY STATUS RESTARTS AGE IP NODE
    nginx 1/1 Running 0 1h 172.16.64.2 k8s-node2
    [root@k8s-master ~]# curl -I 172.16.64.2
    HTTP/1.1 200 OK
    Server: nginx/1.19.0                                                                         查看版本为1.19版
    Date: Wed, 10 Jun 2020 12:56:35 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Tue, 26 May 2020 15:00:20 GMT
    Connection: keep-alive
    ETag: "5ecd2f04-264"
    Accept-Ranges: bytes

      1、修改配置文件

    [root@k8s-master ~]# cp nginx-rc.yaml nginx1.13-rc.yaml 
    [root@k8s-master ~]# vim nginx1.13-rc.yaml
    apiVersion: v1 kind: ReplicationController metadata: name: nginx2 spec: replicas:
    3 selector: app: nginx2 template: metadata: labels: app: nginx2 spec: containers: - name: nginx2 image: 192.168.125.130:5000/nginx:1.19 镜像不能替换 ports: - containerPort: 80 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ :%s#nginx#nginx2#g 把nginx批量替换成nginx2
    [root@k8s-master ~]# vimdiff nginx1.13-rc.yaml nginx.yaml

      2、降级

    [root@k8s-master ~]# kubectl rolling-update nginx -f nginx1.13-rc.yaml --update-period=10s                     降级间隔为10s
    Created nginx2
    Scaling up nginx2 from 0 to 3, scaling down nginx from 3 to 0 (keep 3 pods available, don't exceed 4 pods)
    Scaling nginx2 up to 1
    Scaling nginx down to 2
    Scaling nginx2 up to 2
    Scaling nginx down to 1
    Scaling nginx2 up to 3
    Scaling nginx down to 0
    Update succeeded. Deleting nginx
    replicationcontroller "nginx" rolling updated to "nginx2"
    [root@k8s-master ~]# 

      3、验证版本

    [root@k8s-master ~]# kubectl get pod -o wide
    NAME           READY     STATUS    RESTARTS   AGE       IP            NODE
    nginx          1/1       Running   0          3h        172.16.64.2   k8s-node2
    nginx2-516gh   1/1       Running   0          2m        172.16.74.4   k8s-node1
    nginx2-p56cf   1/1       Running   0          2m        172.16.64.4   k8s-node2
    nginx2-v6t11   1/1       Running   0          1m        172.16.74.2   k8s-node1
    [root@k8s-master ~]# curl -I 172.16.64.4
    HTTP/1.1 200 OK
    Server: nginx/1.13.12                                                       版本为1.13版
    Date: Wed, 10 Jun 2020 14:56:28 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Mon, 09 Apr 2018 16:01:09 GMT
    Connection: keep-alive
    ETag: "5acb8e45-264"
    Accept-Ranges: bytes
  • 相关阅读:
    python笔记目录
    Django 的View(视图)系统
    051_Bootstrap 框架
    050_jQuery 事件
    049_jQuery 操作标签
    048_jQuery
    016-递归函数
    047_BOM_DOM
    046_JS
    045_CSS
  • 原文地址:https://www.cnblogs.com/aqicheng/p/13089411.html
Copyright © 2011-2022 走看看