Skip to content

DEPLOYMENT

Within this first Lab we will create a simple deployment of our example-app. The goal is to successfully pull the application image from a private container repository and make it accessible on your browser.

What you will learn:

  • Create a Deployment
  • Inspect cluster resources
  • Expose the application via a Load Balancer Service


1. Deploy

Create the demo application in a Deployment, using the below specifications:

name: example-app
labels: app = example-app
replicas: 1
image: ghcr.io/thinkportrepo/k8s-example-app:latest
containerPort: 8080
HINT

1. Use the imperative command to create a blueprint file
2. Add the label: app = example-app

Solution

$ kubectl create deployment example-app --image ghcr.io/thinkportrepo/k8s-example-app:latest --port 8080 --dry-run=client -o yaml > example-deploy.yaml


3. Deploy the newly created blueprint
Solution

$ kubectl create -f example-deploy.yaml


- Alternatively, you may take the definition file under 2 + 3 - Deployment and Resourcelimits/2.1-example-app-deploy.yaml as a reference.
- You can also create the deployment by the given definition file:
Solution

$ kubectl create -f "2 + 3 - Deployment and Resourcelimits/2.1-example-app-deploy.yaml"


- If you were just to create a single Pod with the imperative command:
Solution

$ kubectl run example-app --image ghcr.io/thinkportrepo/k8s-example-app:latest --port 8080 --labels app=example-app



When finished, check the results!

  • What state is the Deployment in?
  • How many Pods have been deployed?
  • What are the logs on the pods?
HINT

$ kubectl get deployments
$ kubectl describe deployment [name-of-deployment]
$ kubectl get pods
$ kubectl describe pod [name-of-pod]
$ kubectl logs [name-of-pod]



2. Expose

Create a LoadBalancer service to expose the application externally via AKS.

service name: example-svc-lb
type: LoadBalancer
port: 80
targetPort: 8080
HINT

1. Make use of imperative commands to create a file blueprint. Then edit the blueprint before deploying it:

Solution

$ kubectl expose [...] --dry-run=client -o yaml > [path-to-file]


2. Or create the service directly via imperative commands:
Solution

$ kubectl expose deploy example-app --name example-svc-lb --port 80 --target-port 8080 --type LoadBalancer


3. Take the file under 2 + 3 - Deployment and Resourcelimits/2.2-svc-loadBalancer.yaml as a reference.
4. You can also create the service by the given definition file:
Solution

$ kubectl create -f "2 + 3 - Deployment and Resourcelimits/2.2-svc-loadBalancer.yaml"



When finished, check the results!

  • What’s the external IP of the service?
  • How can you reach the example application in your browser?
HINT

1. When you list all services, you will see the externalIP column:

$ kubectl get services
2. Alternatively you can inspect the service via describe command and look for the externalIP:
$ kubectl describe service example-svc-lb
$ kubectl describe service example-svc-lb | grep -i "Loadbalancer Ingress"
---



3. Access

Access the application in your browser on [externalIP]:[port]

Add entries to the guestbook under /create

List all entries under /list

Try accessing the guestbook from different browsers and create some entries. Take note of the behavior.



4. Delete

Delete the example-app Pod. Wait for the command to be completed.


HINT

$ kubectl delete pod example-app-[id]


Check the results and discuss them.

  • How many Pods are available now?
  • Is the guestbook application still available in your browser?
  • Can you see the guestbook entries that you have made earlier?
HINT

1. Get a list of your pods and check, whether you can watch, if the state of the pods in your cluster changes:

Solution

$ kubectl get pods --help

1. Try this command, right after deleting the Pod one more time:
Solution

$ kubectl get pods -w




END