Kubernetes Hands-on Lab developed by the Azure GBB Team
The objective of the workshop is to get hands-on with the content covered during the day . Attendees will get a set of resources delivered as a starting point, and then go from there to continue building functionality.
Technologies covered:
- Docker tooling
- Azure Container Services
- Kubernetes
- OS: For people not using Linux or Mac please make sure you have the latest version of Windows and have enabled and tested the Subsystem for Linux. Install it from the store using these instructions: https://msdn.microsoft.com/en-us/commandline/wsl/install_guide
- CLI: please install the azure cli from here: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
- Docker: install Docker CE from here: https://docs.docker.com/engine/installation/
- Git: install git using your package manager of choice
- (optional) VS Code: install visual studio code: https://code.visualstudio.com/
In this section, you’ll start off with running a simple docker container on your local machine. The container you’ll run is backed by a simple Redis image which can just be referred to as “redis”.
- Pull the image from the public Docker registry and make sure you see it in your own local repo
- Run a Redis container, exposing port 6379
Tip: find Docker documentation for:
- a working container, which you can test by installing a Redis client:
// on windows, using chocolatey:
choco install redis-64
// on linux, using apt:
sudo apt install redis-tools
// on mac:
brew install redis
- verify you can connect and work with the Redis container:
// try connect with the redis cli, check if redis-cli connects and if counter increases
redis-cli
> incr mycounter
> incr mycounter
- Stop and start the container again, make sure it retains the state where you left off
- Stop and delete the container
In this part, you’ll build your own container image and run it.
The source code for the container to build is published on GitHub here: https://github.com/Azure-Samples/azure-voting-app-redis/tree/master/azure-vote
- Clone the repo locally on your machine
// when using ssh (make sure you have keys setup correctly; if not you might want to try http instead):
git clone [email protected]:Azure-Samples/azure-voting-app-redis.git
// when using http:
git clone https://github.com/Azure-Samples/azure-voting-app-redis.git
- Go into this working directory: .\azure-voting-app-redis\azure-vote\
- Look for the Dockerfile with which to build the image:
- Inpect it
- Build an image, tagged “yourname/azure-vote”
- Spin up a Redis container (see Part 1), find the ip for it and run your freshly built “yourname/azure-vote”. Make sure when you run it, to provide an environment variable with as its name
REDIS
and as its value the ip for the Redis container. This is how our frontend knows where to call into Redis.
Tip: note that the frontend web server will not be able to reach the Redis over "localhost". Every container has its own ip address provisioned automatically by the Docker engine. To get to this ip address, use
docker inspect [container-name]
. Once you get this ip for Redis, give it to the frontend container by theREDIS
environment variable.
Tip: find Docker documentation for building images here
- Verify that you can see your image in your local repository
- You have a successful running web application on http://localhost:8080
We’re now ready to spin up our own Kubernetes cluster in Azure to deploy our containers upon. As a first step, we’ll deploy an empty cluster.
- Create a resource group to deploy your cluster into.
- Create a Kubernetes cluster, using ACS (“Azure Container Service”)
Tip: when deploying through the CLI, there’s an option to have it create/reuse and store the ssh keys automatically, which is quite handy
- Install the
kubectl
command line environment
Tip: you can do so through the
az
azure command line interface
- Configure
kubectl
to point to your freshly created cluster
Tip: also this can be done from the
az
command line
- You have a working Kubernetes cluster and are able to access the web interface from Kubernetes on
http://127.0.0.1:8001/ui
kubectl get nodes
provides you the list of nodeskubectl cluster-info
gives you information on your cluster
Now that we have our cluster up and running, it's time to start deploying a workload on there.
Tip: You might want to install Kubernetes support for VS Code from: https://marketplace.visualstudio.com/items?itemName=ipedrazas.kubernetes-snippets to ease you with yaml file creation.
- Create a manifest for deploying a single pod, containing just our Redis container. (Note that this is not done in production; but it’s good for learning purposes to see how Kubernetes concepts stack up.)
- Deploy the pod onto the cluster using
kubectl
Tip: find the documentation for Kubernetes
Pod
resources online here
- Make sure you can see the new pod on the cluster
- You are able to test it works by connecting to the pod with the Redis command line (redis-cli) and using
kubectl port-forward
, exposing port6379
to your local machine
- Try deleting the pod or the container within it and see if it comes back up
Use the following container images when creating the Kubernetes deployment:
- Redis:
redis
- Frontend:
microsoft/azure-vote-front:redis-v1
Use the environment variable REDIS
and as its value the hostname for the Redis container to indicate how the frontend can communicate with Redis.
- Create a yaml file for the backend (Redis) Deployment and deploy it, exposing port
6379
on the pod level - Create a yaml file for the backend (Redis) Service and deploy it. The service should not be accessible from outside the cluster and should expose Redis’ port
6379
- Create a yaml file for the frontend Deployment and deploy it, exposing port
80
on the pod level and making sure it knows how to find the Redis’ backend - Create a yaml file for the frontend Service and deploy it, exposing port
80
to the public, making sure it is backed by a Load Balancer in Azure
Tip: find the documentation for:
- Kubernetes
Deployment
resources online here- Kubernetes
Service
resources online here
- You have a fully working web application, exposed on the internet
- Try deleting the pod or the container and make sure it comes back up automatically