k8s rs 实验。
注:本文为笔者实验记录,非教程。
环境
# 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文件
# 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"
创建:
kubectl create -f busybox-rs.yaml
查看:
# 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
停止:
kubectl delete -f busybox-rs.yaml