Set up minikube on Ubuntu Server within minutes

Introduction

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).

About minikube

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).

Prerequisites

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).

Estimated time

By following this tutorial, you should be able to get minikube up and running within 20 minutes.

Steps

  1. Get your VM ready
  2. Install Kubectl
  3. Install additional dependencies
  4. Install minikube
  5. Start the minikube
  6. Deploy a sample application
  7. Expose the deployment
  8. Access the service on a web browser
  9. 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:

  1. Log into IBM Cloud.

  2. From the Navigation Menu, click VPC Infrastructure, and then select Virtual server instances.

    Screen capture of the Navigation Menu

  3. Click Create.

  4. Enter a name for your VM in the Name field.

    Screen capture of the Name field within the New virtual server for VPC panel

    Let the Resource group be the default for now unless you have a real need for a unique resource group.

  5. Select a location for hosting your VM.

  6. In the Operating System section, select the 18.04 LTS Ubuntu Linux server image.

    Screen capture of the Operating System menu

  7. Select the profile for your VM.

  8. 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.

  9. Click Create to provision your VM, which will take a few seconds.

  10. 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

Screen capture of the `apt-get install` command output

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 /usr/local/bin directory.

#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.

#sudo -i

Add the minikube and localhost IPs to the NO_PROXY IP list.

#set NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,192.168.99.0/24,192.168.39.0/24

Step 5. Start the minikube

#minikube start --vm-driver=none --docker-env NO_PROXY=$NO_PROXY

Screen capture of the `start` command output

minikube status is up and running.

Screen capture of the minikube status

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

Screen capture of the `create deployment` command output

Check the status of the hello-node deployment by using the kubectl get all command.

Screen capture of 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

Create a LoadBalancer service type to expose the hello-node deployment.

#kubectl expose deployment hello-node --type=LoadBalancer --port=8080

Screen capture of the `expose deployment` command output

List the hello-node service by using the kubectl get services command.

Screen capture of the `kubectl get services` command output

A node port numbered 31662 is allocated by Kubernetes in the default range for node ports such as 30000-32767. The hello-node LoadBalancer service that you created forwards requests made to this port to the 8080 port where the container in your pod is listening.

Let’s curl the internal service IP with 8080 within the cluster to get the response.

Screen capture of the response from the `curl` command

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:

Screen capture of the web browser window

Step 9. Stop minikube

You can stop minikube gracefully from inside your VM with the stop command.

Screen capture of the `stop` command output

You can also stop or pause your VM to avoid incurring VM usage charges.

Summary

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.