Part 2 Flashcards

1
Q

Labels

Create a pod named kplabs-label. The pod should be launched from nginx image. The name of container should be nginx-container. Attach following label to the pod.


  1. env=production
  2. app=webserver
A

apiVersion: v1

kind: Pod

metadata:

name: kplabs-label
namespace: default

labels:

env: production
app: webserver

spec:

containers:

  • name: nginx-container
    image: nginx

kubectl get pods -l env=production

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Deployments

Creat a deployment named kplabs-deployment. The deployment should be launched from nginx image. The deployment should be three replicas. The selector should be based on the label of app=nginx

A

apiVersion: apps/v1

kind: Deployment

metadata:

creationTimestamp: null

labels:

run: kplabs-deployment
name: kplabs-deployment

spec:

replicas: 3

selector:

matchLabels:

run: kplabs-deployment
strategy: {}

template:

metadata:

creationTimestamp: null

labels:

run: kplabs-deployment
app: nginx

spec:

containers:

  • image: nginx
    name: kplabs-deployment
    resources: {}
    status: {}

kubectl get pods -l app=nginx

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Deployments - Rolling Updates and Rollbacks

  1. Create a deployment named kplabs-update.
  2. The deployment should be launched from nginx image.
  3. There should be two replicas.
  4. Verify the status of the deployment.
  5. As part of rolling update, update the image to nginx2:alpine.
  6. Verify the status of deployment.
  7. Perform a rollback to the previous version and Verify the status of deployment.
A

kubectl set image deployment/kplabs-update kplabs-update=nginx2:alpine kubectl rollout undo deployment/kplabs-update kubectl describe deployment/kplabs-update

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Readiness Probe

Launch a pod from the nginx image. Create a readiness probe for the pod.

A

apiVersion: v1

kind: Pod

metadata:

labels:

test: liveness
name: liveness-exec

spec:

containers:

  • name: liveness
    image: nginx

livenessProbe:

exec:

command:

  • service
  • nginx
  • status

initialDelaySeconds: 5

periodSeconds: 5

kubectl exec -it liveness-exec bash

service nginx stop

kubectl get pods will show restart count 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Labels and Selectors

  1. Create a deployment named kplabs-selector.
  2. The pods should be launched from nginx image.
  3. The pods should only be launched in a node which has a label of disk=ssd
  4. Observe the status of deployment.
  5. Add the appropriate label to the worker node and then observe the status of the deployment.
A

kubectl label nodes kubernetes-foo-node-1.c.a-robinson.internal disktype=ssd

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

CronJob

Create a job named kplabs-job. The job should run every minute and should print out the current date.

A

kubectl create cronjob test-job1 –image=busybox –schedule=”*/1 * * * *” – date

kubectl get cronjob -w

kubectl logs test-job2-1582032720-98z9b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly