Fatskills
Practice. Master. Repeat.
Study Guide: Certified Kubernetes Application Developer
Source: https://www.fatskills.com/kubernetes/chapter/certified-kubernetes-application-developer

Certified Kubernetes Application Developer

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~3 min read

Set up alias
alias k='kubectl'

Run a pod
k run {name} --image={imageName} --restart=Never

Dry run to Yaml
-o yaml --dry-run > pod.yaml

Run from yaml
k create -f {filename}.yaml

Show all labels of pods
k get pods --show-labels

Change the label of a pod
k label pod {podname} {newLabel}={newValue} --overwrite

Get all pods and show the value of a given label
k get po -L {labelName}

Get pods with label name and value
k get pods -l {labelName}={labelValue}

Remove a label from existing pods
k label pods {podName} {podName} {labelName}-

Create a pod that will be deployed to a Node that has the label 'accelerator=nvidia-tesla-p100'
apiVersion: v1
kind: Pod
metadata:
name: cuda-test
spec:
containers:
- name: cuda-test
image: "k8s.gcr.io/cuda-vector-add:v0.1"
nodeSelector: # add this
accelerator: nvidia-tesla-p100 # the slection label

Annotate pods nginx1, nginx2, ngingx3 with "description='my description'" value
kubectl annotate po nginx1 nginx2 nginx3 description='my description'

Check the annotations for pod nginx1
kubectl describe po nginx1 | grep -i 'annotations'

Remove the annotations for pods
k annotate po {podName} {podName} description-

Define Kubernetes
an open-source system for automating deployment, scaling and management of containerised applications

Pod
A pod consists of one or more containers which share an IP address, access to storage and a namespace

kubelet agent
Heavy lifter for changes and configuration on worker nodes

Get current kubectl context
k config current-context

Exec into a pod shell
k exec -t {podName} {optional:containerName} -- /bin/sh

Sidecar container
Sits alongside a container in a pod and performs functions which are decoupled from the main application (such as logging).

Adapter container
Modify data, on ingress or egress, to match some other need.

Ambassador container
Allows for access to the outside world without having to implement a service or ingress controller

restartPolicy
Alway, OnFailure or Never

livenessProbe or redinessProbe
httpGet: # or exec or tcpSocket
path: /healthz
port: 8080
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 15
timeoutSeconds: 1

Terminate old pods before running new
strategy:
type: Recreate

PersistentVolume
kind: PersistentVolume
apiVersion: v1
metadata:
name: 10gpv01
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/somepath/data01"

PersistentVolumeClaim
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi

Use a secret as environment variable
env:

- name: PASSWORD
valueFrom:
secretKeyRef:
name: mysql
key: password

Change pod's image
kubectl set image nginx nginx=nginx:1.7.1

Get a pod's IP
k get po -o wide

Check rollout status
k rollout status deploy {deploymentName}

Check rollout history
k rollout history deploy {deploymentName} --revision=3

Undo rollout
k rollout undo deploy {deploymentName} --to-revision=2

Autoscale
kubectl autoscale deploy nginx --min=5 --max=10 --cpu-percent=80

Get horizontal pod autoscaler
k get hpa

Expose a deployment on port 6262
kubectl expose deploy foo --port=6262 --target-port=8080

Pause a deployment
k rollout pause deployment {deploymentName}

Resume a deployment
k rollout resume deployment {deploymentName}

Mount a secret as a volume
containers:
- image: busybox
name: secondapp
volumeMounts:
- mountPath: /mysqlpassword
name: mysql
name: busy
volumes:
- name: mysql
secret:
secretName: {secretName}

Create a config map
k create configmap {name} --from-literal={name}={value}

Security context
apiVersion: v1
kind: Pod
spec:
securityContext:
runAsUser: 1000
containers:
- name: sec-ctx-demo
image: gcr.io/google-samples/node-hello:1.0
securityContext:
runAsUser: 2000
allowPrivilegeEscalation: false

App resource requirements
apiVersion: v1
kind: Pod
spec:
containers:
- name: demo
image: polinux/stress
resources:
limits:
memory: 200Mi
cpu: 200m
requests:
memory: 100Mi
cpu: 100m

Service account
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
serviceAccountName: build-robot

Get logs about a previous instance
kubectl logs nginx -p



ADVERTISEMENT