-
You have completed Lab 01 - Deploying AKS.
-
If you're not familar with
kubectl
, please take a look at Explorekubectl
.
A Pod represents a set of running containers on your cluster - it's the smallest and simplest Kubernetes object.
-
Using
kubectl
, create a new Pod called 'webserver' runningnginx
image.kubectl run webserver --image=nginx --restart=Never
-
Get the status and IP of Pod 'webserver'.
kubectl get pod webserver -o wide
-
Get a detailed description of the pod, including related resources such as events or controllers.
kubectl describe pod webserver
-
Get the status of 'faultywebserver'.
kubectl get pod faultywebserver -o wide
Notice that the Pod status is "ImagePullBackOff". Something is wrong.
-
Identify, and resolve, the issue with 'faultywebserver'.
kubectl describe pod faultywebserver kubectl set image pod faultywebserver faultywebserver=nginx kubectl get pod faultywebserver -o wide
-
Using YAML, create a new Pod called 'web' running
nginx
image.# use kubectl to generate web-pod.yaml kubectl run webserver --image=nginx --restart=Never --dry-run -o yaml > web-pod.yaml # view nginx-pod.yaml cat web-pod.yaml # apply the YAML file kubectl apply -f web-pod.yaml
Notice the use of
--dry-run -o yaml
to generate the yaml, which is then piped into web-pod.yaml.
-
Using
kubectl
, create a new Pod called 'nginx' runningnginx
image. Label the Pod with 'app=v1'.kubectl run nginx --image=nginx --restart=Never --labels=app=v1 # or kubectl run nginx --image=nginx --restart=Never kubectl label pod nginx app=v1
-
Show all Pods in the default namespace, including the Pods' labels.
kubectl get pod --show-labels
-
Change the label of pod 'nginx' to be 'app=v2'
kubectl label pod nginx app=v2 --overwrite
-
Get all Pods with the label 'app=v2'.
kubectl get pod -l app=v2
-
Remove the 'app' label from Pod 'nginx'.
kubectl label pod nginx app-
-
Annotate Pod 'nginx' with "description='my description'".
kubectl annotate pod nginx description='my description'
-
Get logs from 'webserver'.
kubectl logs webserver
-
Retrieve a list of all the files within the
nginx
container running on 'webserver' pod.kubectl exec webserver -- ls
A deployment is an API object that manages a replicated application. A Deployment controller provides declarative updates for Pods and ReplicaSets.
-
Create a yaml file for a Deployment running a
nginx
container, with five replicas, and save it as mydeploy.yaml.kubectl run mydeploy --image=nginx --replicas=5 --dry-run -o yaml > mydeploy.yaml
This is another great example where you can use
--dry-run -o yaml
to generate the required yaml. -
Create a Deployment using mydeploy.yaml.
kubectl apply -f mydeploy.yaml
-
View the Deployment 'mydeploy', the associated ReplicaSet and Pods.
kubectl get deployment,rs,pod
-
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 mydeploy=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 2 instance.
kubectl scale deploy mydeploy --replicas=2
A Service is an abstract way to expose an application running on a set of Pods.
-
Expose the deployment 'mydeploy' on port 80. Observe that a service is created.
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 withwget
:# 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.
SignalR based application that allows website users to light fireworks and display on all the connected site users. You can light single or multi shot using the app. There is also a button that can stimulate a crash /home/admin. Pressing the button again will make the application run again.
Port Exposed:
- 80
Images on Docker Hub:
- Green: kunalbabre/fireworks:green
- Blue: kunalbabre/fireworks:blue
- Red: kunalbabre/fireworks:red
- Yellow: kunalbabre/fireworks:yellow
Trigger fireworks manually:
- Trigger Single: /home/singleshot
- Trigger Multishot: /home/multishot
Environment variables:
SIGNALR_CS
: (optional) if you wish to scale-out you can provide connection string for Redis or Azure SignalRAPP_COLOR
: (works with latest tag) you can specify theme color for the app (red,green, blue, yellow)
Health Monitoring:
-
Liveness: /home/isRunning
- returns HTTP 200 if the application is alive
- returns HTTP 400 if the application has crashed
-
Readiness: /home/isRunning
- returns HTTP 200 if the application is alive
- returns HTTP 400 if the application has crashed
-
All operations in this exercise should be performed in the
fireworks
namespace (already been created for you).hint
kubectl config set-context $(kubectl config current-context) --namespace=<namespace>
-
Create Deployment called 'fireworks' using the image
kunalbabre/fireworks:red
in the namespace 'fireworks'.hint
kubectl create deployment <name> --image <image name>
-
Expose the deployment
firework
on port 80. Use aLoadBalancer
service called 'fireservice'.hint
kubectl expose deployment <deployment-name> --name <service-name> --port=80 --type <service-type>
-
Wait for the external IP to be allocated. Once available, navigate to the IP address in the web browser.
hint
kubectl get svc -w
-
Scale the deployment 'fireworks' to 5 replicas. Observe the Pods being created.
hint
# using edit command to update replica count kubectl edit deployment <deployment name> # or, using the scale command kubectl scale deployment <deployment name> --replicas=5 # finally, you can watch pods being created kubectl get po -w
-
Update the deployment 'fireworks' to use image
kunalbabre/fireworks:latest
.hint
# using edit command to update container image kubectl edit deployment <deployment name> # or, using set image command kubectl set image deploy <deployment name> fireworks=<New Image Name>
-
Configure the 'fireworks' pods to only accept traffic when ready and auto restart if crashed.