kubernetes exr6 LABELS AND SELECTORS
1
2
3
4
5
6
7
8
# We have deployed a number of PODs. They are labelled with tier, env and bu. How many PODs exist in the dev environment (env)?
# Use selectors to filter the output
kubectl get pods --selector env=dev --no-headers | wc -l
or
k get pods -l env=dev --no-headers | wc -l
1
2
3
# How many PODs are in the finance business unit (bu)?
kubectl get pods --selector bu=finance --no-headers | wc -l
1
2
3
4
5
6
7
# How many objects are in the prod environment including PODs, ReplicaSets and any other objects?
kubectl get all --selector env=prod --no-headers | wc -l
or
kubectl get all -l env=prod
1
2
3
4
# Identify the POD which is part of the prod environment, the finance BU and of frontend tier?
kubectl get all --selector env=prod,bu=finance,tier=frontend
kubectl get all -l env=prod,bu=finance,tier=frontend
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
30
31
32
33
# A ReplicaSet definition file is given replicaset-definition-1.yaml.
# Try to create the replicaset.
# There is an issue with the file. Try to fix it.
kubectl apply -f replicaset-definition-1.yaml
- ReplicaSet: replicaset-1
- Replicas: 2
# The ReplicaSet "replicaset-1" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"tier":"nginx"}: `selector` does not match template `labels
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-1
spec:
replicas: 2
selector:
matchLabels:
tier: nginx
template:
metadata:
labels:
tier: nginx
spec:
containers:
- name: nginx
image: nginx
tier의 selector 값과
template의 metadata의 labels값을 같게 해준다
kubectl apply -f replicaset-definition-1.yaml