Java OpenResty Spring Spring Boot MySQL Redis MongoDB PostgreSQL Linux Android Nginx 面试 小程序 Arthas JVM AQS juc Kubernetes Docker DevOps


Kubernetes Pod 控制器 ReplicaSet

Kubernetes 大约 3279 字

查看帮助

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
阅读 424 · 发布于 2022-03-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb

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

扫描二维码关注我
昵称:
随便看看 换一批