Skip to content

Latest commit

 

History

History
98 lines (68 loc) · 2.33 KB

4. Deployments.md

File metadata and controls

98 lines (68 loc) · 2.33 KB

Deployments

Create a yaml file for a Deployment running a nginx container, with five replicas, and save it as mydeploy.yaml.

#Tip use command to generate yaml and then update replica counts in the yaml
kubectl create deploy mydeploy --image=nginx -o yaml --dry-run > mydeploy.yaml

This is another great example where you can use --dry-run -o yaml to generate the required yaml.

Create Deployment using mydeploy.yaml

kubectl apply -f .\mydeploy.yaml

View the Deployment and Replica Sets

kubectl get deploy,rs,po

Modify the image used by 'mydeploy' to use image nginx:1.16.0 and observe the update as it's applied.

# set the deployment image
kubectl set image deployment mydeploy nginx=nginx:1.16.0

# observe how the update gets applied 
kubectl get rs -w

View the rollout history for 'mydeploy' and roll back to the previous revision.

# view previous rollout revisions and configurations.
kubectl rollout history deploy mydeploy

# rollback to the previous rollout.
kubectl rollout undo deploy mydeploy

# observe how rollowing update gets applied 
kubectl get rs -w

Scale 'mydeploy' to 1 instance

kubectl scale deploy mydeploy --replicas=1

Expose the deployment 'mydeploy' on port 80 (ClusterIP). Observe that a service is created.

# Tip try writing the yaml file instead of command below
kubectl expose deployment mydeploy --port 80
kubectl get svc mydeploy

Confirm that a Cluster IP has been created.

kubectl get svc mydeploy -o jsonpath='{.spec.clusterIP}'

Using the Pod's Cluster IP, create a new temporary Pod using busybox and 'hit' the IP with wget:

# get the service's Cluster IP
kubectl get svc mydeploy -o jsonpath='{.spec.clusterIP}'

# run busybox
kubectl run busybox --rm --image=busybox -it --restart=Never -- sh

# from inside the container
wget -O- <cluster-ip>:80
exit

Change to service type of 'mydeploy' from the ClusterIP to LoadBalancer. Find the Public IP address and browse to the application.

# edit the service
kubectl edit svc mydeploy

# change "type: ClusterIP" to "type: LoadBalancer"

# get the assigned external IP
kubectl get svc -w

Note: This may take a few minutes to complete.

Delete all resources in the current namespace

kubectl delete all --all