Exercise - Deploy An Application On Your Azure Kubernetes Service Cluster - Training - Microsoft Learn
Exercise - Deploy An Application On Your Azure Kubernetes Service Cluster - Training - Microsoft Learn
" 100 XP
In this exercise, you'll deploy your company's website as a test app onto Azure Kubernetes Service
(AKS). The website is a static website with an underlying technology stack of HTML, CSS, and
JavaScript. It doesn't receive as many requests as the other services and provides us with a safe
way to test deployment options.
7 Note
The code for the web app is available in this GitHub repository if you want to explore the
source code further. Also, this sample app will be deployed on a Linux node pool only.
) Important
You need your own Azure subscription to run this exercise, and you might incur charges. If
you don't already have an Azure subscription, create a free account before you begin.
Kubernetes groups containers into logical structures called pods, which have no intelligence.
Deployments add the missing intelligence to create your application. Let's create a deployment
file.
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/5-exercise-deploy-app 1/7
28/10/22, 10:00 Exercise - Deploy an application on your Azure Kubernetes Service cluster - Training | Microsoft Learn
2. In Cloud Shell, create a manifest file for the Kubernetes deployment called deployment.yaml
by using the integrated editor.
Bash
touch deployment.yaml
4. Open the deployment.yaml file, and add the following code section of YAML.
YAML
# deployment.yaml
metadata:
In this code, you added the first two keys to tell Kubernetes the apiVersion and kind of
manifest you're creating. The name is the name of the deployment. You'll use it to identify
and query the deployment information when you use kubectl .
Tip
For more information about apiVersion and what values to put in this key, see the
official Kubernetes documentation. Find a link at the end of this module.
5. A deployment wraps a pod. You make use of a template definition to define the pod
information within the manifest file. The template is placed in the manifest file under the
deployment specification section.
YAML
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/5-exercise-deploy-app 2/7
28/10/22, 10:00 Exercise - Deploy an application on your Azure Kubernetes Service cluster - Training | Microsoft Learn
etadata:
name: contoso-website
spec:
labels:
app: contoso-website
Pods don't have given names when they're created inside deployments. The pod's name will
be the deployment's name with a random ID added to the end.
Notice the use of the labels key. You add the labels key to allow deployments to find and
group pods.
6. A pod wraps one or more containers. All pods have a specification section that allows you to
define the containers inside that pod.
YAML
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: contoso-website
spec:
metadata:
labels:
app: contoso-website
spec:
- name: contoso-website
The containers key is an array of container specifications because a pod can have one or
more containers. The specification defines an image , a name , resources , ports , and other
important information about the container.
All running pods will follow the name contoso-website-<UUID> , where UUID is a generated
ID to identify all resources uniquely.
7. It's a good practice to define a minimum and a maximum amount of resources that the app
is allowed to use from the cluster. You use the resources key to specify this information.
YAML
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: contoso-website
spec:
metadata:
labels:
app: contoso-website
spec:
containers:
- image: mcr.microsoft.com/mslearn/samples/contoso-website
name: contoso-website
resources:
cpu: 100m
memory: 128Mi
cpu: 250m
memory: 256Mi
Notice how the resource section allows you to specify the minimum resource amount as a
request and the maximum resource amount as a limit.
8. The last step is to define the ports this container will expose externally through the ports
key. The ports key is an array of objects, which means that a container in a pod can expose
multiple ports with multiple names.
YAML
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: contoso-website
spec:
metadata:
labels:
app: contoso-website
spec:
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/5-exercise-deploy-app 4/7
28/10/22, 10:00 Exercise - Deploy an application on your Azure Kubernetes Service cluster - Training | Microsoft Learn
spec:
nodeSelector:
kubernetes.io/os: linux
containers:
- image: mcr.microsoft.com/mslearn/samples/contoso-website
name: contoso-website
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
Notice how you name the port by using the name key. Naming ports allows you to change
the exposed port without changing files that reference that port.
9. Finally, add a selector section to define the workloads the deployment will manage. The
selector key is placed inside the deployment specification section of the manifest file. Use
the matchLabels key to list the labels for all the pods managed by the deployment.
YAML
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: contoso-website
spec:
metadata:
labels:
app: contoso-website
spec:
nodeSelector:
kubernetes.io/os: linux
containers:
- image: mcr.microsoft.com/mslearn/samples/contoso-website
name: contoso-website
resources:
requests:
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/5-exercise-deploy-app 5/7
28/10/22, 10:00 Exercise - Deploy an application on your Azure Kubernetes Service cluster - Training | Microsoft Learn
equests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
name: http
7 Note
In an AKS cluster which has multiple node pools (Linux and Windows), the deployment
manifest file listed above also defines a nodeSelector to tell your AKS cluster to run the
sample application's pod on a node that can run Linux containers.
Bash
Output
deployment.apps/contoso-website created
2. Run the kubectl get deploy command to check if the deployment was successful.
Bash
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/5-exercise-deploy-app 6/7
28/10/22, 10:00 Exercise - Deploy an application on your Azure Kubernetes Service cluster - Training | Microsoft Learn
Output
3. Run the kubectl get pods command to check if the pod is running.
Bash
Output
Continue T
https://learn.microsoft.com/en-us/training/modules/aks-deploy-container-app/5-exercise-deploy-app 7/7