Scheduling - Labels and Selectors
Ju Young Pang
·2025. 1. 25. 14:36
Q) We have deployed a number of PODs. They are labelled with tier, env and bu. How many PODs exist in the dev enviroment (env)?
$ k get po --selector='env=dev' -A --no-headers | wc -l
7
A) 7
Q) How many PODs are in the finance business unit (bu)?
$ k get po -A --selector bu=finance --no-headers | wc -l
6
A) 6
Q) How many objects are on prod environment? (including all kubernetes objects such as replicasets, deployments, etc.)
$ k get all -A --selector env=prod --no-headers | wc -l
7
A) 7
Q) Identify the POD which is part of the prod environment, the finance BU and of frontend tier?
$ k get po -A -l env=prod,bu=finance,tier=frontend
NAMESPACE NAME READY STATUS RESTARTS AGE
default app-1-zzxdf 1/1 Running 0 7m26s
A) app-1-zzxdf
Q) A ReplicaSet definition file is given replicaset-definition-1.yaml. Attempt to create the replicaset; you will encounter an issue with the file. Try to fix it.
$ k apply -f replicaset-definition-1.yaml
The ReplicaSet "replicaset-1" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"tier":"nginx"}: `selector` does not match template `labels`
$ vi replicaset-definition-1.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-1
spec:
replicas: 2
selector:
matchLabels:
tier: front-end
template:
metadata:
labels:
# tier: nginx
# template must match the selector > matchLabels
tier: front-end
spec:
containers:
- name: nginx
image: nginx
$ k apply -f replicaset-definition-1.yaml
replicaset.apps/replicaset-1 created
'Kubernetes > CKA' 카테고리의 다른 글
Scheduling - Node Affinity (0) | 2025.01.26 |
---|---|
Scheduling - Taints and Tolerations (0) | 2025.01.26 |
Scheduling - Manual Scheduling (0) | 2025.01.18 |
Core Concepts - Imperative Commands (0) | 2025.01.18 |
Core Concepts - Services (0) | 2025.01.16 |