Part 2 Flashcards
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.
- env=production
- app=webserver
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
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
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
Deployments - Rolling Updates and Rollbacks
- Create a deployment named
kplabs-update
. - The deployment should be launched from
nginx
image. - There should be two replicas.
- Verify the status of the deployment.
- As part of rolling update, update the image to
nginx2:alpine
. - Verify the status of deployment.
- Perform a rollback to the previous version and Verify the status of deployment.
kubectl set image deployment/kplabs-update kplabs-update=nginx2:alpine kubectl rollout undo deployment/kplabs-update kubectl describe deployment/kplabs-update
Readiness Probe
Launch a pod from the nginx
image. Create a readiness probe for the pod.
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
Labels and Selectors
- Create a deployment named
kplabs-selector
. - The pods should be launched from
nginx
image. - The pods should only be launched in a node which has a label of
disk=ssd
- Observe the status of deployment.
- Add the appropriate label to the worker node and then observe the status of the deployment.
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
CronJob
Create a job named kplabs-job
. The job should run every minute and should print out the current date.
kubectl create cronjob test-job1 –image=busybox –schedule=”*/1 * * * *” – date
kubectl get cronjob -w
kubectl logs test-job2-1582032720-98z9b