Skip to content

Latest commit

 

History

History
72 lines (56 loc) · 1.8 KB

File metadata and controls

72 lines (56 loc) · 1.8 KB

Replica Sets

Learn about replica sets
Tips and Tricks

For simulated Practice problems visit KillerCoda.
  1. Run a pod p1 with image nginx and label tier=frontend.

    Solution

    k run p1 --image=nginx --labels=tier=frontend

  2. Create a replicaSet rs1 with replicas=3 and having pod template of p1 pod.

    Solution

    replica_set.yaml

    apiVersion: apps/v1
    kind: ReplicaSet
    metadata:
      name: rs1
      labels:
        tier: frontend
    spec:
      replicas: 3 # no of pods
      selector:
        matchLabels:
          tier: frontend
      template: # pod p1 template details
        metadata:
          labels:
            tier: frontend
        spec:
          containers:
          - image: nginx
            name: p1
          dnsPolicy: ClusterFirst
          restartPolicy: Always

  3. Delete two of pods belonging to rs1 replicaSet, check the pods again they are reinstated to a total of 3.

    Solution

    # check the pods belonging to rs1 replica set
    #one is p1 that we created in the first step, other two will be named in pattern rs1-xxxxx
    k get po
    
    k delete po p1 rs1-xxx --force
    
    # list the pods
    # you will notice that the no of pods belonging to rs1 replica set are respawing, till they are 3 in number
    k get po