Kubernetes Pod 控制器 ReplicaSet

Kubernetes About 3,279 words

查看帮助

kubectl explain ReplicaSet

yml 文件

replicas: 3:指定运行3个实例。

apiVersion: apps/v1
kind: ReplicaSet   
metadata:
  name: pc-replicaset
  namespace: dev
spec:
  replicas: 3
  selector: 
    matchLabels:
      app: nginx-pod
  template:
    metadata:
      labels:
        app: nginx-pod
    spec:
      containers:
      - name: nginx
        image: nginx:1.17.1

查看副本集信息

kubectl get rs -n dev -o wide

输出:

[root@localhost ~]# kubectl get rs -n dev -o wide
NAME            DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES         SELECTOR
pc-replicaset   3         3         3       10m   nginx        nginx:1.17.1   app=nginx-pod

查看运行的 Pod

kubectl get pods -n dev -o wide

输出:

[root@localhost ~]# kubectl get pods -n dev -o wide
NAME                  READY   STATUS    RESTARTS   AGE   IP           NODE                    NOMINATED NODE   READINESS GATES
pc-replicaset-jv4dn   1/1     Running   0          12m   10.42.0.9    localhost.localdomain   <none>           <none>
pc-replicaset-9ksk7   1/1     Running   0          12m   10.42.0.11   localhost.localdomain   <none>           <none>
pc-replicaset-2c5gz   1/1     Running   0          12m   10.42.0.10   localhost.localdomain   <none>           <none>

扩缩容

edit 方式

使用edit编辑副本集名为pc-replicaset的配置。

该命令进入的编辑页面与Vim用法一致。

kubectl edit rs pc-replicaset -n dev

replicas修改为6,输出:

[root@localhost ~]# kubectl get pods -n dev -o wide
NAME                  READY   STATUS    RESTARTS   AGE     IP           NODE                    NOMINATED NODE   READINESS GATES
pc-replicaset-jv4dn   1/1     Running   0          15m     10.42.0.9    localhost.localdomain   <none>           <none>
pc-replicaset-9ksk7   1/1     Running   0          15m     10.42.0.11   localhost.localdomain   <none>           <none>
pc-replicaset-2c5gz   1/1     Running   0          15m     10.42.0.10   localhost.localdomain   <none>           <none>
pc-replicaset-l6shs   1/1     Running   0          2m25s   10.42.0.13   localhost.localdomain   <none>           <none>
pc-replicaset-zc8fj   1/1     Running   0          2m25s   10.42.0.14   localhost.localdomain   <none>           <none>
pc-replicaset-wpbpn   1/1     Running   0          2m25s   10.42.0.12   localhost.localdomain   <none>           <none>

scale 方式

kubectl scale rs pc-replicaset --replicas=2 -n dev

replicas调整为2,输出:

[root@localhost ~]# kubectl get pods -n dev -o wide
NAME                  READY   STATUS    RESTARTS   AGE   IP           NODE                    NOMINATED NODE   READINESS GATES
pc-replicaset-jv4dn   1/1     Running   0          19m   10.42.0.9    localhost.localdomain   <none>           <none>
pc-replicaset-9ksk7   1/1     Running   0          19m   10.42.0.11   localhost.localdomain   <none>           <none>

镜像升级

备注:也可以使用edit方式

kubectl set image rs pc-replicaset nginx=nginx:1.17.2 -n dev

查看实例,输出:

[root@localhost ~]# kubectl get rs -n dev -o wide
NAME            DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES         SELECTOR
pc-replicaset   2         2         2       32m   nginx        nginx:1.17.2   app=nginx-pod

删除 ReplicaSet

通过名称删除

kubectl delete rs pc-replicaset -n dev

通过yml文件删除

kubectl delete -f pc-replicaset.yml
Views: 1,401 · Posted: 2022-03-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh