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 the Cloud Shell, use nano or vi to create a file named azure-vote.yaml.
- 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
---
- 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:
Now that we've deployed the application, we will test it.