(CKA) Certified Kubernetes Administrator Training {Minikube}

How to Run Minikube (Kubernetes) in AWS EC2 (Ubuntu) Linux

If you are studying for the Certified Kubernetes Administrator (CKA) exam one of the very first step you may want to tale is to install minikube. We will do just that, but installing it on a AWS EC2 Ubuntu 18.04 Linux instance.

Minikube is just one of the way that Kubernetes can be installed. The four major installation types are briefly presented below:

  • All-in-One Single-Node Installation: With all-in-one, all the master and worker components are installed on a single node. This is very useful for learning, development, and testing. This type should not be used in production. Minikube is one such example.
  • Single-Node etcd, Single-Master, and Multi-Worker Installation: In this setup, we have a single master node, which also runs a single-node etcd instance. Multiple worker nodes are connected to the master node.
  • Single-Node etcd, Multi-Master, and Multi-Worker Installation: In this setup, we have multiple master nodes, which work in an HA mode, but we have a single-node etcd instance. Multiple worker nodes are connected to the master nodes.
  • Multi-Node etcd, Multi-Master, and Multi-Worker Installation: In this mode, etcd is configured in a clustered mode, outside the Kubernetes cluster, and the nodes connect to it. The master nodes are all configured in an HA mode, connecting to multiple worker nodes. This is the most advanced and recommended production setup.

Next, we outline the requirements to run Minikube on our AWS EC2 Instance:

  • kubectl: binary used to access any Kubernetes cluster. Generally, it is installed before starting Minikube, but we can install it later, as well. If kubectl is not found while installing Minikube, we will get a warning message, which can be safely ignored (just remember that we will have to install kubectl later).
  • VirtualBox or KVM hypervisors (not required): Minikube supports a –vm-driver=none option that runs the Kubernetes components on the host and not in a VM. Docker is required to use this driver, but no hypervisor. If you use –vm-driver=none, be sure to specify a bridge network for Docker. Otherwise, it might change between network restarts, causing loss of connectivity to your cluster. We will indeed use this method as we don’t want to install VirtualBox within a virtual instance (AWS EC2)
  • Internet connection on first run.

Installation of Minikube on EC2 Ubuntu 18.04 LTS


In order to run minikube you need at least 2 CPUs, so we are going to use the t2.medium instance type which provisions 2 CPU and 4 GB of RAM which is fair enough for running minikube. However, please note that these instance type will do incur charges as it is not part of the AWS free tier. We have tried to install minikube on a t2.micro and it wasn’t possible.

Run a EC2 instance with the following setup

You can use the AWS Management Console for creating the instance or the AWS CLI if you already have it configured. Feel free to check our post related to AWS EC2 if you need some guidance on how to create instances on AWS EC2.
The details for the instance are:

  • AMI Ubuntu Server 18.04 LTS (HVM), SSD Volume Type
  • Instance Type t2.medium
  • Storage 8 GB (gp2)
  • Security Group Name: Minikube Security Group – SSH, 0.0.0.0/0
  • Key Pair Create your own keypair.

or with the AWS CLI commands:

aws ec2 create-security-group --group-name Minikube --description "Minikube Security Group"
aws ec2 authorize-security-group-ingress --group-id  --protocol tcp --port 22 --cidr 0.0.0.0/0
aws ec2 run-instances --image-id ami-09f4cd7c0b533b081 --instance-type t2.medium --key-name AWSKey --security-group-ids 

Connect using SSH into your created EC2 Instance using your keypair.

ssh -i <keypair>.pem ubuntu@<ipv4_public_ip> 


Install kubectl on AWS Linux instance

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl


Install Docker on AWS Linux instance

sudo apt-get update && sudo apt-get install docker.io -y

Install Minikube on AWS Linux instance

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/


Check Minikube Version on AWS Linux instance

 minikube version



Running Minikube on AWS EC2 Ubuntu Linux


Become root

 sudo -i


Start Minikube

We are going to use the –vm-driver=none switch. The rationale is we don’t want to install a Hypervisor like VirtualBox on the AWS instance, we just want minikube to run using the host resources.

minikube start --vm-driver=none

Output:

πŸ˜„  minikube v1.0.0 on linux (amd64)
 🀹  Downloading Kubernetes v1.14.0 images in the background …
 πŸ’‘  Tip: Use 'minikube start -p ' to create a new cluster, or 'minikube delete' to delete this one.
 πŸƒ  Re-using the currently running none VM for "minikube" …
 βŒ›  Waiting for SSH access …
 πŸ“Ά  "minikube" IP address is 172.31.83.16
 🐳  Configuring Docker as the container runtime …
 🐳  Version of container runtime is 18.09.2
 βŒ›  Waiting for image downloads to complete …
 ✨  Preparing Kubernetes environment …
 🚜  Pulling images required by Kubernetes v1.14.0 …
 πŸ”„  Relaunching Kubernetes v1.14.0 using kubeadm … 
 βŒ›  Waiting for pods: apiserver proxy etcd scheduler controller dns
 πŸ“―  Updating kube-proxy configuration …
 πŸ€”  Verifying component health …..
 🀹  Configuring local host environment 
.....

Check the status of Minikube

 minikube status


If you see the status as β€˜running’ then we can now run kubectl commands.

Let us run our first container

kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080

Expose the container ports so that we can access it.

kubectl expose deployment hello-minikube --type=NodePort

Find where port 8080 in container exposed in EC2 Instance port.

kubectl get services
NAME             TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
hello-minikube   NodePort    10.96.87.65   <none>        8080:31516/TCP   17s
kubernetes       ClusterIP   10.96.0.1     <none>        443/TCP          16h

Note: Port 31516 is the EC2 Instance Port where the Port 8080 of the container is exposed.

The EC2 Instance Port changes each time you expose a port, you may have been given a different value than what I have.

kubectl get services command shows the list of services and their exposed ports.

Let us check by accessing this via a web browser on our local computer. But first we need to edit our EC2 Security Group.

Edit Security Group of the EC2 Instance to be accessible

You can edit your security group using the AWS Management console or an AWS CLI command like the following:

aws ec2 authorize-security-group-ingress --group-id  --protocol tcp --port 31516 --cidr 0.0.0.0/0


Access the our container via the EC2 Instance Port on a web browser.

Output from our Containter running on Minikube (Kubernete)

If you see an output similar to the above, Congratulations! You have your first Minikube (Kubernetes) deployment UP, running and accessible on the internet!

Now you can relax and clean everything up πŸ™‚

Delete the exposed service (port)

kubectl delete services hello-minikube


Delete the deployed container (hello-minikube)

kubectl delete deployment hello-minikube


Stopping Minikube/Shutting Down the Cluster

minikube stop

Remember also to stop the AWS Instance to reduce billing charges.

So that is all for now, you have your minikube setup UP and Running. If you need assistance with Kubernetes or AWS don’t hesitate to contact us.