3. Kubernetes Cluster

In the previous exercise, you put the Go app into a Docker container and pushed it to the Docker Hub repository. So now you need to deploy this application from your Docker Hub repository to your local Kubernetes cluster.

Note

This exercise is slightly different from the original one - it was modified according to more practical use cases and connect student progress from the previous lessons.

Preparation

Install VirtualBox and Vagrant

  1. Install VirtualBox: sudo apt install virtualbox

  2. Install Vagrant: sudo apt-get update && sudo apt-get install vagrant

Up Virtual Machine

  1. Change directory to exercises: cd exercises

  2. Init virtual machine: vagrant init

  3. Up the virtual machine: vagrant up

  4. Check the status of virtual machine: vagrant status

Useful Vagrant Commands

  • Shut down virtual machine forcefully: vagrant halt

  • Suspend the virtual machine: vagrant suspend

  • Restart virtual machine: vagrant up

Find out more in Vagrant Cheat Sheet

Exercise 3.1 - Create Kubernetes Cluster

  • Create k3s Kubernetes cluster on the local machine using Virtual Box and Vagrant.

Exercise 3.2 - Deploy Application to the Kubernetes Cluster

  • Run go-helloworld app at the Kunernetes cluster from the Docker Hub.

  • Deploy go-helloworld to the Kubernetes cluster from the Docker Hub.

Exercise 3.3 - Define and Deploy Kubernetes Resources

  • Deploy the following resources using the kubectl command:

    • a namespace:
      • name: demo

      • label: tier: test

    • a deployment:
      • image: nginx:alpine

      • name: nginx-apline

      • namespace: demo

      • replicas: 3

      • labels: app: nginx, tag: alpine

    • a service:
      • expose the above deployment on port 8111

      • namespace: demo

    • a configmap:
      • name: nginx-version

      • containing key-value pair: version=alpine

      • namespace: demo

Note

Nginx is one of the public Docker images, that you can access and use for your exercises or testing purposes.

Make sure the following tasks are completed:

You have created a Namespace
You have created a Deployment
You have created a Service
You have created a Configmap

Additional Resourses

  1. Kubernetes Tutorial for Beginners - 4 Hour Video Course

  2. Official Kubernetes Tutorials

  3. Kubernetes Hands-on Labs

  4. Vagrant Documentation Resources

  5. Vagrant Cheat Sheet

  6. K3s Lightweight Kubernetes

  7. Stopping and starting Kubernetes cluster

  8. Organizing Cluster Access Using kubeconfig Files

  9. How to Manage Kubernetes With Kubectl

  10. Explore kubectl Cheat Sheet

  11. Kubernetes Config file

  12. Using kubectl to Create a Deployment

  13. How to Delete Pods from a Kubernetes Node

  14. Use Port Forwarding to Access Applications in a Cluster