Kubernetes deployment samples for AKS and .NET Core
Repo is here
- docker.io/dgkanatsios:0.1 - normal working image tagged 0.1
- docker.io/dgkanatsios:0.2 - normal working image tagged 0.2
- docker.io/dgkanatsios:0.2-startupfails - app fails to start
- docker.io/dgkanatsios:0.2-healthfails - health probe fails after 10 seconds
Run watch -n 0.5 kubectl get pods -o wide --sort-by=.metadata.creationTimestamp
kubectl cluster-info
: get info about AKS clusterkubectl get nodes -o wide
: get info about nodes
kubectl create deploy nginx --image=nginx
: create an nginx deploymentkubectl expose deploy nginx --port=80 --type=LoadBalancer
: expose it to the outside worldkubectl get deploy nginx -o yaml
: see some YAML for the deploymentkubectl delete svc nginx && kubectl delete deploy nginx
: cleanup
kubectl apply -f deploy.yaml
: this will create version 0.1kubectl get po --show-labels
: observe that all Pods have the same label as the Deployment templatekubectl get rs --show-labels
: same for the replica setkubectl describe rs ....
: check the details for the replica setkubectl describe po | grep -C 3 'Controlled By'
: see that the Pods "belong" to the Replica Set
kubectl get svc
: get the public IP and check IP/hello from a browser to verify that the deployment workskubectl run -it busybox --rm --image=busybox sh
andwget -q0- aksdotnet-deployment/hello
: see that version 0.1 is returned- Get the Pod name in the browser, do
kubectl exec -it PodName -- bash
to connect to the Pod. Runapt update && apt install net-tools tcpdump procps
, then...ps -aux
to see the running processes (observer that the .NET process has a PID of 1). Try also runningtop
for real-time informationnetstat -tulpn
to see the open ports from processestcpdump port 80
and refresh the browser to see the packets coming in
- Do
kubectl logs
for one of the pods to see logs of incoming requests
kubectl get po
: get the pod nameskubectl delete po ....
: delete a random Podkubectl get po
: verify that a new Pod was createdkubectl describe rs
: check the ReplicaSet events
kubectl scale deployment aksdotnet-deployment --replicas=10
: this will scale the deployment to 10 replicaskubectl describe deploy
: check the events about replica set being scaledkubectl describe rs
: check the events about the Pods being created
kubectl edit deploy aksdotnet-deployment
: update tag to a non-existent one (alternatively you can dokubectl set image deployment aksdotnet-deployment aksdotnet docker.io/dgkanatsios/aksdotnet:wrong-tag --record
or edit the yaml file and thenkubectl apply -f deploy.yaml --record
)kubectl get rs
andkubectl rollout status deploy aksdotnet-deployment
: see what happens with maxUnavailablekubectl rollout history deploy aksdotnet-deployment
: see the deployment historykubectl rollout history deploy aksdotnet-deployment --revision=2
: see details about a specific revisionkubectl rollout undo deploy aksdotnet-deployment
: undo the last deploymentkubectl get deploy aksdotnet-deployment
: see that everything is good again
kubectl edit deploy aksdotnet-deployment
: update tag to 0.2 - Pod template changes so an upgrade is triggeredkubectl rollout status deployment aksdotnet-deployment
: see the status of the deploymentecho $?
: get the last exit code (ofkubectl rollout status deploy
) and see that it is not zerokubectl describe deploy aksdotnet-deployment
: see that the version was upgraded to 0.2kubectl rollout history deployment aksdotnet-deployment
: see all deploymentskubectl get rs
: see that there is one ReplicaSet per deployment update
kubectl edit deploy aksdotnet-deployment
: change tag to 0.2-startupfails and observe what happens with the pods (kubectl get po -w
)
kubectl edit deploy aksdotnet-deployment
: change tag to 0.2-healthfails and observe what happens with the pods (kubectl get po -w
)
For more kubectl fun, check out my CKAD-exercises repo.