Kubernetes Concepts Flashcards
How are Yaml files used in Kubernetes?
- used as inputs for creation of objects such as pods/deployments/replicas/services
What are the always existing top-level fields in a object-definition Yaml file? (top/root-level properties, required)
apiVersion: kind: metadata: spec:
What is the apiVersion?
- Version of the Kubernetes API used for creating objects
Name a few possible kind/version combinations?
Pod / v1
Service / v1
ReplicaSet / apps/v1
Deployment / apps/v1
What describes the kind-property?
What kind of object are we trying to create?
- Pod
- Service
- ReplicaSet
- Service
- Deployment
- etc
What is the metadata property?
Data about the object.
Like name, labels etc
Form of a dictionary
metadata: name: xxx labels: app: myapp
What can be part of the metadata property? What is the difference in that to labels?
- only name or labels or other specifics exptected by Kubernetes
- labels can have any free-chosen key-value pairs
What is part of the spec property?
- specification/additional information of the object to be created
- different for different objects
- Dictionary
spec: containers (list/array): - name: nginx-container image: nginx
How do we trigger the creation of an object from a .yaml file?
kubectl create -f pod-definition.yaml
-f references to files
multiple files can be added
-f file1 -f file2
kubectl create -f FILENAME [flags]
How can the ‘kubectl apply -f’ command be used?
- similiar to ‘kubectl create -f command’
What does the ‘spec’ property of the ‘pod’ kind look like?
spec: containers: - name: nginx image: nginx
Differten look for other kinds
How does one define an environemnt variable for a pod?
spec: containers: - name: postgres image: postgres env: - name: POSTGRES_PASSWORD value: mysecretpassword
What does the READY column in the output of the kubectl get pods command indicate?
Running containers in pod / total containers in pod
What does ‘kubectl run redis –image=redis123 –dry-run=client -o yaml’ do?
-previews a specific image on the cluster and gives the output in a yaml format
What does the suffix ‘> redis.yaml’ do the command ‘kubectl run redis –image=redis123 –dry-run=client -o yaml’?
It pipes the yaml result of the command into its own file, creating the file
What are Controllers?
- brain behind Kubernetes - the processes that monitor Kubernetes objects and respond accordingly
In connection with work loads, why do we need a replication controller/replica set?
- to create multiple pods and share the workload across them
What does the replication controller/replica set do?
- helps us run multiple instances of a single pot in the Kubernetes Cluster
- providing high availability
- even with a single pod the controller helps by automatically bringing up a new container instance if the old one fails
- ensures that the specified number of pods is running at all times
- scales with high demand
How far does a replication controller/replica set span?
- spans across multiple nodes in the cluster
In what connection to replication controller and replica set stand?
- same purpose but are not the same
- replica set replaces replication controller
How do we create a replication controller?
- yaml definition file
apiVersion: v1 kind: ReplicationController metadata: name: myapp-rc labels: app: myapp type: frontend spec: template: metadata: name: myapp-pod labels: app: myapp type: frontend spec: containers: - name: nginx-container image: nginx replicas: 3
How is the spec of a replication controller set up?
- nested yaml file
- includes a template with the spec of the pod to be replicated, without apiVersion and kind
- includes replicas with the needed number of pod-replicas
With what command can we get more information about replication controllers?
kubectl get replicationcontroller
What hint does a pod give about the replicationController used to create it?
name starts with the metadata name of the replicationController used
How does the replicaSet Yaml look?
apiVersion: apps/v1 kind: ReplicaSet metadata: name: myapp-replicaset labels: app: myapp type: front-end spec: template: metadata: ... spec: containers: ... replicas: 3 (same column as replicas) selector: matchLabels: type: front-end
What are the differences in the yaml file between replicaSet and replicationController?
apiVersion: apps/v1 vs. v1
kind: ReplicaSet vs. ReplicationController
+ ReplicaSet has additional ‘selector’
Why does the ReplicaSet have a selector-property in the spec?
- because replicaSet can also manage pods that were not creates as part of the replica set creation
- previously created pods with the label selected under selector will also be taken into consideration when creating replicas
Why do we label our objects in Kubernetes?
We can use labels to monitor a certain selection of resources.
For instance with the ReplicaSet
What is a ReplicaSet gonna do, when even before the replicaSet is created the number of correctly labeled pods is higher then the needed number of pods?
- no new instances of pods are going to be created
How do we update a ReplicaSet yaml if we want to increase the number of pods?
Multiple ways:
- increasing the number under ‘replicas’ to the needed amount, then run ‘kubectl replace -f filename’
- run the command ‘kubectl scale –replicas=6 -f replicaset-definition.yaml’ OR ‘kubectl scale –replicas=6 TYPE NAME’ (kubectl scale –replicas=6 replicaset myapp-replicaset)
- Using the file name as input will NOT increase the number of replicas in the original yaml file
In a ReplicaSet how are the selector and the template metadata connected?
The label in the selector and in the pod-definition need to be the same.
The replicaSet selector needs to select the pods, created by the set.
What happens, when more pods exist under a label, managed by a replicaSet, then there should be?
- the pod that was supposed to be created is terminated
What does the command ‘kubectl edit replicaset myapp-replicaset’ do and what is special about it?
- it opens up the specified yaml file to be changed
- the shown file is a in-memory copy NOT the original, changes are not persisted but only applied to the current running instance of that file
What are rolling updates? What are they used for?
- updating pod-instances one after the other
- used, so that the user experience is not negatively impacted
What does a Deployment enable?
Gives the capability to:
- upgrade the underlying instances seamlessly using rolling updates
- pause the environment, so that new commands are not immediately applied
- resume a deployment
- rollback recent updates/changes
How does the Deployment.Yaml look like?
Looks like the ReplicaSet Yaml, except for ‘kind’ which is ‘Deployment’
What does the command ‘kubectl get all’ do?
Shows all created Kubernetes objects
What does the command ‘kubectl create deployment –help’ do?
Shows all possible follow ups and exmpales for commands
How does the Deployment rollout process / update go?
- deployment gets created
- created deployment triggers a new rollout
- the new rollout creates a new deployment revision (revision 1)
- when the application is upgraded/container version is updated a new rollout is triggered and a new deployment revision is created (revision 2)
- enables rollback if necessary
With what command can we see the status of the rollout?
‘kubectl rollout status deployment/myapp-deployment’
With what command can we see the history of a rollout?
‘kubectl rollout history deployment/myapp-deployment’
What kind of Deployment Strategies exist?
- Recreate Strategy (Not default): First destroy all instances and then deploy all again, updated (application inaccessible due to downtime)
- Rolling Update Strategy (default): Take down the older version and bring up the new one, one by one. Seamless deployment
How are the different Deployment strategies visible?
- in details from ‘kubectl describe deployment xxx’
- Recreate: scales down to 0 and then back up to before value
- RollingUpdate: scales one replicaset up and another one down at the same time, step by step
How do we update a deployment?
Several ways,
- changes to file and then ‘kubectl apply -f deployment-definition.yaml’
- kubectl set image deployment/myapp-deployment nginx-containter=nginx:1.9.1 (but then the yaml has a different configuration)
How does a Deployment Upgrade work?
- newly created deployment creates a new replicaSet automatically, this then creates the number of pods
- when upgraded, a new replicaSet is created
- then is scales up the new replicaSet, while simultaneaosly scaling down the older replicaSet
How can we rollback a rollout?
‘kubectl rollout undo deployment/myapp-deployment
What does the option ‘–record’ do when added to commands like ‘kubectl create -f deployment.yaml’
- instructs Kubernetes to record the cause for change
- currently deprecated
How can you specify the version of an image in the yaml file?
image: nginx:1.18
With what command do you run a sh-script?
sh nameOfFile
How does one set an alias in Linux?
alias k=’kubernetes’