Skip to content

Latest commit

 

History

History
106 lines (78 loc) · 2.26 KB

File metadata and controls

106 lines (78 loc) · 2.26 KB

Labels and Selectors

Labels and Selectors
Tips and Tricks

For simulated Practice problems visit KillerCoda.
  1. name a pod sumo with image nginx and label it tier=frontend

    Solution

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

    --OR--

    # update metadata of pod yaml
    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels: # add label
        tier: frontend
      name: sumo
    spec:
      containers:
      - image: nginx
        name: sumo
        resources: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
    status: {}

    verify labels on pods running

      k get po --show-labels

  2. create 3 pods named one, two and three with image nginx:alpine and label them resource=alpha, resource=beta and resource=gama respectively.

    Solution

    k run one --image=nginx:alpine --labels=resource=alpha
    
    k run two --image=nginx:alpine --labels=resource=beta
    
    k run three --image=nginx:alpine --labels=resource=gama

  3. Add label tier=backend to pods one,two and three

    Solution

    k label pod one two three tier=backend

  4. Add label app_version=v1 to pods having labels tier=frontend or tier=backend.

    Solution

    k label pod -l "tier in (frontend,backend)" app_version=v1

  5. Update label app_version=v2 on pod two

    Solution

    k label pod two app_version=v2 --overwrite

  6. Remove label app_version on pod one

    Solution

    k label pod one app_version-