Deploying the application

In this section, we are going to deploy the application to the cluster. For this, we need to define a Kubernetes manifest file. This defines the desired state for the cluster, such as what container images to run. We are going to use a manifest to create all the objects that are needed to deploy our sample application. This sample application is the Azure vote application and consists of a Python application and a Redis instance. The manifest will include two Kubernetes deployments: one for the frontend Python application and one for the backend Redis Cache. Two Kubernetes services will be created as well; that is, an internal service for the Redis instance and an external service so that we can access the vote application from the internet.

In this demonstration, we are going to create the manifest file manually and deploy it manually to the cluster. However, in more real-world scenarios, you can use Azure Dev Spaces (https://docs.microsoft.com/en-us/azure/dev-spaces/) to debug your code directly in the AKS cluster. You can use Dev Spaces to work together with others on your team and across OS platforms and development environments.
  1. In the Cloud Shell, use nano or vi to create a file named azure-vote.yaml. 
  2. Copy in the following YAML definition. Here, we have the backend application, beginning with the deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-back
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-back
template:
metadata:
labels:
app: azure-vote-back
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: azure-vote-back
image: redis
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 6379
name: redis
---
  1. Then, we have the service for the backend application:
apiVersion: v1
kind: Service
metadata:
name: azure-vote-back
spec:
ports:
- port: 6379
selector:
app: azure-vote-back
---

Next, we have the deployment for the frontend application:

apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-front
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-front
template:
metadata:
labels:
app: azure-vote-front
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: azure-vote-front
image: microsoft/azure-vote-front:v1
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
env:
- name: REDIS
value: "azure-vote-back"
---

After this, we have the service:

apiVersion: v1
kind: Service
metadata:
name: azure-vote-front
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: azure-vote-front

Now, deploy the application using the azure-vote manifest file:

kubectl apply -f azure-vote.yaml

The application will be deployed. This will result in the following output:

The output of deploying the application

Now that we've deployed the application, we will test it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset