作者注:本文仅为笔者学习记录,不具任何参考意义。
k8s rs 实验。 注:本文为笔者实验记录,非教程,另会不定时更新。
环境 1 2 3 4 5 # kubectl get node NAME STATUS ROLES AGE VERSION edge-node Ready <none> 15m v1.17.0 edge-node2 Ready <none> 16m v1.17.0 ubuntu Ready master 67d v1.17.0
ReplicaSet 在新版本的 Kubernetes 中建议使用 ReplicaSet(简称为RS )来取代 ReplicationController。ReplicaSet 跟 ReplicationController 没有本质的不同,只是名字不一样,并且 ReplicaSet 支持集合式的 selector(ReplicationController 仅支持等式)。
不建议单独使用,与deployment结合使用。
测试yaml文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 # vim busybox-rs.yaml apiVersion: apps/v1 # 直接用v1不支持 kind: ReplicaSet # 声明rs metadata: name: frontend # 指定本资源(此处为rs)的名称 labels: app: busybox tier: frontend spec: replicas: 2 # !! 此处为2个副本 selector: matchLabels: tier: frontend matchExpressions: - {key: tier, operator: In, values: [frontend]} template: metadata: labels: app: busybox ## 指定标签 tier: frontend spec: containers: - name: busybox image: latelee/busybox # 镜像名称,真实存在 imagePullPolicy: IfNotPresent command: - sleep - "3600"
创建:
1 kubectl create -f busybox-rs.yaml
查看:
1 2 3 4 # kubectl get pod -l tier=frontend NAME READY STATUS RESTARTS AGE frontend-789xk 1/1 Running 0 80s frontend-stqvm 1/1 Running 0 80s
停止:
1 kubectl delete -f busybox-rs.yaml