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

二、定义yml文件

[root@k8s-master rc]# vim k8s_rc.yaml 
apiVersion: v1
kind: ReplicationController  #资源类型
metadata:
  name: nginx
spec:
  replicas: 5  #副本5
  selector:
    app: myweb
  template:  #模板
    metadata:
      labels:
        app: myweb
    spec:
      containers:
      - name: myweb
        image: 10.0.0.11:5000/nginx:1.13
        ports:
        - containerPort: 80

三、创建rc资源

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

四、查看资源

[root@k8s-master rc]# kubectl get pod
NAME          READY     STATUS    RESTARTS   AGE
nginx-4pm88   1/1       Running   0          6s
nginx-4xksg   1/1       Running   0          6s
nginx-nkmfp   1/1       Running   0          6s
nginx-q0w8r   1/1       Running   0          6s
nginx-qbz57   1/1       Running   0          6s
test          2/2       Running   9          4h

五、删除其中一个副本,会立即启动一个新的

[root@k8s-master rc]# kubectl delete pod nginx-q0w8r  
pod "nginx-q0w8r" deleted
[root@k8s-master rc]# kubectl delete pod 
error: resource(s) were provided, but no name, label selector, or --all flag specified
[root@k8s-master rc]# kubectl get pod 
NAME          READY     STATUS    RESTARTS   AGE
nginx-4pm88   1/1       Running   0          2m
nginx-4xksg   1/1       Running   0          2m
nginx-nkmfp   1/1       Running   0          2m
nginx-nz3l7   1/1       Running   0          23s
nginx-qbz57   1/1       Running   0          2m
test          2/2       Running   9          4h

ps:如果其他的资源改了标签达到了rc定义资源副本的数量,rc会释放掉存活时间最短的资源


0 Comments

发表评论

Avatar placeholder

邮箱地址不会被公开。 必填项已用*标注