Task: Deploy a Container to Kubernetes

Video: Deploy a Web Site to an Azure Kubernetes Service

Estimated time: 20 minutes for task

Goal

Create a Kubernetes manifest and deploy it to an Azure Kubernetes service.

Pre-requisites

  1. Azure subscription
  2. Azure container registry with a custom image
  3. Azure Kubernetes service with the ACRPull role on the ACR.

Requirements

  1. Create a Kubernetes manifest file
  2. Deploy a Kubernetes manifest file
  3. Verify the deployment

Requirement 1: Create a Kubernetes manifest file

For this requirement you will create a manifest file to deploy the custom image stored in your ACR. You will deploy three instances of the container with a load balanced front end.

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: pythonserver
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: pythonserver
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: service
        image: <your ACR server>/taskimage:1.0
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 500m
---
apiVersion: v1
kind: Service
metadata:
  name: service-endpoint
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: pythonserver

Note: Be sure to use your ACR server name for the image attribute. Also, be very careful with indentation, yaml is a bit picky.

Requirement 2: Deploy a Kubernetes manifest file

For this requirement you will use the Kubernetes CLI (kubectl) to deploy your manifest file. The steps below assume you are using the Azure bash cloud shell to complete the requirement. If you have both the Azure CLI and the Kubernetes CLI installed locally, you can complete the requirement locally.

az aks get-credentials -n kubernetes -g 'task-kubernetes'
  kubectl apply -f ./task-kube-app.yaml

Requirement 3: Verify the deployment

For this requirement you will monitor the kubernetes service to verify that the pods are running and that the service gets a public IP address. You will then browse to the public IP address and confirm that you get the expected result.

kubectl get pod
kubectl get service service-endpoint --watch

Note: Once the public IP shows up, press Ctrl-C to step watching.

Note: Refreshing the page should return a different result. Each pod (instance) is assigned a different host name and the service will "round-robin" between them.

Clean up

Note: Other tasks use a virtual machine with Docker installed and this registry. If you plan on completing other container related exercises, you may want to de-allocate the virtual machine rather than removing it, likewise you may not want to delete the registry yet.

Solution

Having trouble completing this task? View the demonstration video to see how to do it.