Kubernetes is an open source container orchestration platform for automated deployment, scaling, and managing of containerized applications. This tutorial covers a quick and easy method for getting up and running with Kubernetes by using minikube on a virtual private cloud (VPC).
minikube is a tool that makes it easy to run Kubernetes locally. It runs a single-node Kubernetes cluster inside a virtual machine (VM) on your laptop. minikube is for people who want to try Kubernetes and is also for those who want to develop with it on a day-to-day basis. Provisioning a VM to run an Ubuntu Server where you can install and run minikube is seamless with IBM Cloud.
With a managed multi-node Kubernetes cluster, you typically have to manage multiple control plane and worker nodes. By contrast, with minikube you can view, edit, and control single-node Kubernetes clusters, which are miniature versions of full-fledged Kubernetes clusters that have both the control plane and worker features functioning on one node. Another advantage of having a minikube Kubernetes cluster installed in your VM is that you can stop, or pause, the VM to avoid charges for the times when you are not using it. And when you restart the VM, the whole Kubernetes environment comes back seamlessly. So, let’s start by setting up a VM with Ubuntu Server version 18.04 long-term support (Ubuntu Server 18.04 LTS).
You must have the following in order to complete the steps in this tutorial:
- IBM Cloud account. If you do not have an IBM Cloud account, register for one using your email address. (Note: The steps in this tutorial require access to a Pay-As-You-Go or Subscription account to create a virtual server instance with IBM Cloud Virtual Server for VPC. When you upgrade to Pay-as-you-go, you get access to the entire IBM Cloud catalog of services and a USD 200 credit that is valid for 30 days and can be applied to any service.)
- Ubuntu VM with 2 CPUs and 2 GB of RAM.
- Basic Linux skills.
- Familiarity with Kubernetes commands (see links in Step 2).
By following this tutorial, you should be able to get minikube up and running within 20 minutes.
- Get your VM ready
- Install Kubectl
- Install additional dependencies
- Install minikube
- Start the minikube
- Deploy a sample application
- Expose the deployment
- Access the service on a web browser
- Stop minikube
Step 1. Get your VM ready
Remember that a VM with a minimum of 2 CPUs or more and 2GB of RAM is recommended for installing and running a minikube Kubernetes cluster. It is quick and easy to get such a VM from IBM Cloud or any other cloud provider. Following are the brief steps to create such a VM on IBM Cloud:
Log into IBM Cloud.
From the Navigation Menu, click VPC Infrastructure, and then select Virtual server instances.
Enter a name for your VM in the Name field.
Let the Resource group be the default for now unless you have a real need for a unique resource group.
Select a location for hosting your VM.
In the Operating System section, select the 18.04 LTS Ubuntu Linux server image.
Select the profile for your VM.
Keep 100 GB as the default Boot volume and 10 GB for the Data volume. You can also leave the default values for the Networking and Network interfaces for testing purposes.
Click Create to provision your VM, which will take a few seconds.
Open the Navigation Menu and navigate to the Resource List to see your VM details, such as the IP address to connect to it. Note down your IP address here because you will need it later.
Step 2. Install Kubectl
Kubectl is the command line tool for Kubernetes to interact with the cluster from the command line.
Referring now to the Kubernetes kubectl install instructions, let’s install Kubectl.
#sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2 #curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - #echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list #sudo apt-get update #sudo apt-get install -y kubectl
Step 3. Install additional dependencies
minikube requires connection tracking (conntrack) dependency for execution of integration tests. At the time of writing this tutorial, the 18.04 LTS Ubuntu Linux server image does not contain this dependency so let’s install it.
#sudo apt-get install conntrack
Step 4. Install minikube
Before installing minikube, let’s install Docker on this VM to run containers, pods, and Kubernetes components. Other container runtimes are also supported, such as cri-o and containerd.
#sudo apt-get install -y docker.io
Download the minikube package, make it executable, and move it to the
#curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 #chmod +x minikube #sudo mv minikube /usr/local/bin
Start up a root shell for running minikube as your root user.
Add the minikube and localhost IPs to the NO_PROXY IP list.
Step 5. Start the minikube
#minikube start --vm-driver=none --docker-env NO_PROXY=$NO_PROXY
minikube status is up and running.
Step 6. Deploy a sample application
Now let’s try a quick deployment named
hello-node by using a container image named
echoserver previously stored on the Google Cloud container image registry (
gcr), with the following command:
#kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
Check the status of the
hello-node deployment by using the
kubectl get all command.
As you can see in the output of the
kubectl get all command, a pod and a deployment are created named
hello-node-7567d9fdc9-64tzx. Congratulations! In the next step, you make
hello-node visible via a load balancer service.
Step 7. Expose the deployment
LoadBalancer service type to expose the
#kubectl expose deployment hello-node --type=LoadBalancer --port=8080
hello-node service by using the
kubectl get services command.
A node port numbered 31662 is allocated by Kubernetes in the default range for node ports such as 30000-32767. The
LoadBalancer service that you created forwards requests made to this port to the 8080 port where the container in your pod is listening.
curl the internal service IP with 8080 within the cluster to get the response.
Step 8. Access the service on a web browser
You might have to check your firewall and VM configuration to allow port 31662 to be accessible on the internet or even just outside your VM.
If you open the web browser window with the minikube single node instance external IP and port 31662, you should see a response that is similar to the one in the following screen capture image:
Step 9. Stop minikube
You can stop minikube gracefully from inside your VM with the
You can also stop or pause your VM to avoid incurring VM usage charges.
Congratulations! You successfully installed minikube on your VM and deployed a sample application on the single-node Kubernetes cluster. You can now start to deploy and manage your Kubernetes workloads with minikube.
Extend your knowledge about Kubernetes by watching the Overview of Kubernetes session from the recent Open Source Contributor’s Conference. You can also learn more about minikube within its documentation.