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.
kubectl apply -f .\mydeploy.yaml
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 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
kubectl scale deploy mydeploy --replicas=1
# Tip try writing the yaml file instead of command below
kubectl expose deployment mydeploy --port 80
kubectl get svc mydeploy
kubectl get svc mydeploy -o jsonpath='{.spec.clusterIP}'
# 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.
kubectl delete all --all