In Namespace pluto there is single Pod named holy-api. It has been working okay for a while now but Team Pluto needs it to be more reliable. Convert the Pod into a Deployment with 3 replicas and name holy-api. The raw Pod template file is available at /opt/course/9/holy-api-pod.yaml.
Please create the Deployment and save its yaml under /opt/course/9/holy-api-deployment.yaml.
There are multiple ways to do this, one is to copy an Deployment example from https://kubernetes.io/docs and then merge it with the existing Pod yaml. That's what we will do now:
cp /opt/course/9/holy-api-pod.yaml /opt/course/9/holy-api-deployment.yaml # make a copy!
vim /opt/course/9/holy-api-deployment.yaml
Now copy/use a Deployment example yaml and put the Pod's metadata: and spec: into the Deployment's template: section:
# /opt/course/9/holy-api-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: holy-api # name stays the same
namespace: pluto # important
spec:
replicas: 3 # 3 replicas
selector:
matchLabels:
id: holy-api # set the correct selector
template:
# => from here down its the same as the pods metadata: and spec: sections
metadata:
labels:
id: holy-api
name: holy-api
spec:
containers:
- env:
- name: CACHE_KEY_1
value: b&MTCi0=[T66RXm!jO@
- name: CACHE_KEY_2
value: PCAILGej5Ld@Q%{Q1=#
- name: CACHE_KEY_3
value: 2qz-]2OJlWDSTn_;RFQ
image: nginx:1.17.3-alpine
name: holy-api-container
volumeMounts:
- mountPath: /cache1
name: cache-volume1
- mountPath: /cache2
name: cache-volume2
- mountPath: /cache3
name: cache-volume3
volumes:
- emptyDir: {}
name: cache-volume1
- emptyDir: {}
name: cache-volume2
- emptyDir: {}
name: cache-volume3
To indent multiple lines using vim you should set the shiftwidth using :set shiftwidth=2. Then mark multiple lines using Shift v and the up/down keys.
To then indent the marked lines press > or < and to repeat the action press .
Next create the new Deployment:
k -f /opt/course/9/holy-api-deployment.yaml create
➜ k -n pluto get pod | grep holy
NAME READY STATUS RESTARTS AGE
holy-api 1/1 Running 0 19m
holy-api-5dbfdb4569-8qr5x 1/1 Running 0 30s
holy-api-5dbfdb4569-b5clh 1/1 Running 0 30s
holy-api-5dbfdb4569-rj2gz 1/1 Running 0 30s
k -n pluto delete pod holy-api --force --grace-period=0
➜ k -n pluto get pod,deployment | grep holy
pod/holy-api-5dbfdb4569-8qr5x 1/1 Running 0 2m4s
pod/holy-api-5dbfdb4569-b5clh 1/1 Running 0 2m4s
pod/holy-api-5dbfdb4569-rj2gz 1/1 Running 0 2m4s
deployment.extensions/holy-api 3/3 3 3 2m4s