CKAD Code Examples
Equality-based label requirement - answer=,==,!=
Set-based label requirements - answerin,notin,exists
kubectl imperative cmds - answerscale, annotate, label, set <field>, edit, patch
Using --edit to modify objects before creation - answerkubectl create --edit -f
/tmp/srv.yaml
configuration file for a Pod that has the annotation imageregistry:
https://hub.docker.com/ - answerapiVersion: v1 kind: Pod metadata: name: annotations-
demo annotations: imageregistry: "https://hub.docker.com/" spec: containers: - name:
nginx image: nginx:1.14.2 ports: - containerPort: 80
https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
Field selectors, ex: filter pods by name "foo" + status.phase "Pending" - answerlet you
select Kubernetes resources based on the value of one or more resource fields with
equality ops & can chain with comma-seperated
ex: kubectl get pods --field-selector metadata.name=foo,status.phase=Pending
Deployment that creates ReplicaSet w/ 3 nginx Pods - answerapiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
, - name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
main parts: replicas, selector, template
create Job with command, Never restart policy, 4 retrys, 3 completions, 2 parallel runs,
finish in 5s - answerapiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
completions: 3
parallelism: 2
activeDeadlineSeconds: 5
main parts: spec.template.spec.containers, command, restartPolicy, backoffLimit,
activeDeadlineSeconds
https://kubernetes.io/docs/concepts/workloads/controllers/job/#running-an-example-job
create CronJob w/ arg & print time every minute - answerapiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
Equality-based label requirement - answer=,==,!=
Set-based label requirements - answerin,notin,exists
kubectl imperative cmds - answerscale, annotate, label, set <field>, edit, patch
Using --edit to modify objects before creation - answerkubectl create --edit -f
/tmp/srv.yaml
configuration file for a Pod that has the annotation imageregistry:
https://hub.docker.com/ - answerapiVersion: v1 kind: Pod metadata: name: annotations-
demo annotations: imageregistry: "https://hub.docker.com/" spec: containers: - name:
nginx image: nginx:1.14.2 ports: - containerPort: 80
https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
Field selectors, ex: filter pods by name "foo" + status.phase "Pending" - answerlet you
select Kubernetes resources based on the value of one or more resource fields with
equality ops & can chain with comma-seperated
ex: kubectl get pods --field-selector metadata.name=foo,status.phase=Pending
Deployment that creates ReplicaSet w/ 3 nginx Pods - answerapiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
, - name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
main parts: replicas, selector, template
create Job with command, Never restart policy, 4 retrys, 3 completions, 2 parallel runs,
finish in 5s - answerapiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
completions: 3
parallelism: 2
activeDeadlineSeconds: 5
main parts: spec.template.spec.containers, command, restartPolicy, backoffLimit,
activeDeadlineSeconds
https://kubernetes.io/docs/concepts/workloads/controllers/job/#running-an-example-job
create CronJob w/ arg & print time every minute - answerapiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args: