4.Replicaset和ReplicationController

kubectl create -f {rs yam fille | rc yam fille}

rs_nginx.yml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx
  labels:
    tier: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      name: nginx
      labels:
        tier: frontend
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

注意:新版本才支持Replicaset,相比ReplicationController,Replicaset支持new set-based selector

查看Replicaset:kubectl get rs

横向扩展pod数:kubectl scale rs {rs name} --replicas={pod 数}

apiVersion: v1
kind: ReplicationController 
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

查看ReplicationController:kubectl get rc

删除ReplicationController:kubectl delete -f {rc yaml file}

横向扩展pod数:kubectl scale rc {rc name} --replicas={pod 数}

Last updated

Was this helpful?