For this lab, you'll need to be in the ~/environment/eks/labs/05-deployments
directory in Cloud9:
$ cd ~/environment/eks/labs/05-deployments
Check the deployment definition deployment.yaml
in the Cloud9 editor.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-server-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web-server
template:
metadata:
labels:
app: web-server
spec:
containers:
- name: server
image: nginx:1.7.9
- How many pods will this deployment manage?
- What will the deployment be called?
- What names will be given to the pods in our deployment?
Apply the deployment configuration to your cluster.
$ kubectl apply -f deployment.yaml
You can query the deployment in the cluster:
$ kubectl get deployments
$ kubectl get pods
$ kubectl get pods -l app=web-server
Scale the deployment to 5 replicas:
$ kubectl scale deployment web-server-deployment --replicas=5
$ kubectl get pods
# Pick one of the pods to perform a request
$ kubectl port-forward web-server-deployment-xxxx-xxxxx 8080:80 &
$ curl localhost:8080
$ fg
# Ctrl + C to close the port forward
You can scale the deployment by editing the replicas:
$ kubectl edit deployment web-server-deployment
# set the replicas to 3
$ kubectl get pods
$ kubectl get pods -l app=web-server
$ kubectl get deployments
Update the deployment image to use apache instead:
$ kubectl set image deployment web-server-deployment server=httpd
# OR
$ kubectl edit deployment web-server-deployment
# change spec.template.spec.containers.image to httpd
Check the status of our update:
$ kubectl rollout status deployment web-server-deployment
# OR
$ kubectl get pods
# OR
$ kubectl get pod -l app=web-server -L app
Can we see our change?
$ kubectl get pods
# Pick one of the pods to perform a request
$ kubectl port-forward web-server-deployment-xxxx-xxxxx 8080:80 &
$ curl localhost:8080
$ fg
# Ctrl + C to close the port forward
The pods have now been deployed with the apache server.