k8s部署rc资源ReplicationController

k8s 部署rc资源ReplicationController

RC:副本控制器

保证指定数量的pod始终存活。rc通过标签选择器来关联pod

创建rc

[root@ pod]#: cat k8s_rc.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 5            #副本数量
  selector:
    app: myweb
  template:
    metadata:
      labels:
        app: myweb
    spec:
      containers:
      - name: myweb
        image: 192.168.64.129:5000/nginx:v1
        ports:
        - containerPort: 80



kubectl create -f k8s_rc.yam

查看状态

[root@ pod]#: kubectl get rc
NAME      DESIRED   CURRENT   READY     AGE
nginx     5         5         5         47m
[root@ pod]#: kubectl get pod
NAME          READY     STATUS    RESTARTS   AGE
nginx         1/1       Running   1          2d
nginx-4mnq0   1/1       Running   0          28m
nginx-g4rgx   1/1       Running   0          47m
nginx-jbx7g   1/1       Running   0          47m
nginx-sght0   1/1       Running   0          47m
nginx-z9mr8   1/1       Running   0          47m

rc 为版本控制数 ,可以指定创建几个pod 也可用滚动升级

rc的滚动升级

准备将要升级的版本

[root@ pod]#: cat k8s_rc2.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx2
spec:
  replicas: 5
  selector:
    app: myweb2
  template:
    metadata:
      labels:
        app: myweb2
    spec:
      containers:
      - name: myweb2
        image: 192.168.64.129:5000/nginx:v2
        ports:
        - containerPort: 80

ps:名字必须于源rc的名字不能相同
标签也不能与源rc的标签相同

kubectl rolling-update nginx -f k8s_rc2.yaml --update-period=10s

rolling-update 滚动升级
nginx 指定升级的rc
-f k8s_rc2.yaml 想升级到的rc 文件
--update-period 升级周期 (生产环境可延长时间)

回滚同理

你可能感兴趣的:(k8s部署rc资源ReplicationController)