Running Minikube in AWS EC2 (Ubuntu)

If you are studying Kubernetes and having a hard time running Minikube on an EC2 Instance, you are not alone. I had a hard time doing it when it was my first time.

Below are the steps (and some comments) that I took to help me run Minikube on my EC2 Instance.

Installation of Minikube on EC2 Ubuntu

1. Run a public EC2 Server with the following setup

AMI Ubuntu Server 18.04 LTS (HVM), SSD Volume Type
Instance Type t2.micro
Storage 8 GB (gp2)
Tags – Key: Name
– Value: Minikube
Security Group Name: Minikube Security Group
– SSH, 0.0.0.0/0
Later we will be editing this.
Key Pair Create your own keypair.
You will need this to SSH to your EC2 Instance

The above setup is within the AWS Free Tier so you could try Minikube on EC2 without spending money. But you can run Minikube on a bigger instance if you like.

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

ssh [email protected]<ipv4_public_ip> -i <keypair>.pem

3. Install kubectl

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

4. Install Docker

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

Minikube requires Docker.

5. Install Minikube

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

6. Check Minikube Version

minikube version

We have now successfully installed Minikube!

Let’s test it!

Running Minikube on EC2 Ubuntu

Become a root user.

sudo -i

If you are not comfortable running commands as root, you must always add sudo before the commands minikube and kubectl.

2. Start Minikube

minikube start --vm-driver=none

Do not worry about the warning. As long as you see the message ‘Kubectl is now configured to use the cluster.’ you have successfully ran Minikube.

Note: In the Install Minikube documentation from Kubernetes.io it says that you need to enable virtualization by accessing the computer’s BIOS. For EC2 Instances we do not have access to the BIOS since AWS EC2 instance is a Virtual Machine. Thus we are using the --vm-driver=none tag. No need to install a Hypervisor (VirtualBox or KVM)

3. Check the status of Minikube

minikube status

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

4. Let us run our first container

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

5. Expose the container ports so that we can access it.

kubectl expose deployment hello-minikube --type=NodePort

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

kubectl get services

Note: Port 30263 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.

7. Edit Security Group of the EC2 Instance to be access

The goal is for us to be able to access the EC2 Instance Port (30263 for me) via the internet.

EC2 >> (Network & Security) Security Groups >> Minikube Security Group >> Ingress

Press Edit. Then Add Rule.

Add the following.

Type Custom TCP Rule
Protocol TCP
Port Range 30263 (the port given to you by the kubectl get services command)
Source Custom
0.0.0.0/0 (Accessible via the internet)

Click Save.

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

The address is <ipv4_public_ip>:<ec2_port>.

My EC2 Instance has an IPv4 Public IP of 13.250.43.8. And since my hello-minikube port 8080 is exposed on port 30263, the address that I placed on my browser is 13.250.43.8:30263.

See the request_uri of the page displayed by the web browser, it says that I am accessing via port 8080.

I accessed my container deployment using Chrome on my laptop. You can use any web browser you like (Safari, Internet Explorer, Edge, Firefox, etc.)

Now that we know that we can access our container, let us finish this and clean up.

9. Delete the exposed service (port)

kubectl delete services hello-minikube

10. Delete the deployed container (hello-minikube)

kubectl delete deployment hello-minikube

Stopping Minikube/Shutting Down the Cluster

minikube stop

I hope the above helps when you want to use Minikube on EC2 Ubuntu.

If there are errors, comments, suggestions, or clarifications you can comment them below.

24 thoughts on “Running Minikube in AWS EC2 (Ubuntu)”

  1. Hi! Thank you so much for such an easy-to-follow article! It helped me to get my first minikube up and running on a free EC2 instance without any problem.

    1. I’d suggest you throw in 4 gigs of RAM to the instance and try again. This seem to have worked for me (apparently)!

  2. HI, Thanks for the detailed steps.
    But I am struck at below step ‘ minikube start –vm-driver=none’

    …….. ..after some logs ……..below waiting for pods hungs for long time.
    – Pulling images required by Kubernetes v1.14.0 …
    : Relaunching Kubernetes v1.14.0 using kubeadm …
    : Waiting for pods: apiserver proxy

    I could start service and cluster.
    But accessing from browser http://: – will give “- Host not found. DNS error “. I had followed step-7 as-well. i.e., EC2 >> (Network & Security) Security Groups >> Minikube Security Group >> Ingress.

    Still no luck. Even curl command also says connection refused.
    curl $(minikube service hello-minikube –url)

    Am I missing something ? Appreciate if this can be cracked.

    Thanks.
    Venkat

  3. One step is missing in this procedure.
    In order to forward the traffic to the service you must run:
    $ kubectl port-forward –address 0.0.0.0 svc/hello-minikube 30263:80
    (with the appropriate port)
    Otherwise, you will get connection refused

      1. t2.large is not free.
        t2.micro is free for the first 12 months of your AWS Account.

        If your AWS Account is more than 12 months and you need a really cheap instance go for a t3a.micro.

  4. Thank you for this tutorial. I was able to start minikube but encountered this error on one of the steps.
    # kubectl run hello-minikube –image=gcr.io/google_containers/echoserver:1.4 –port=8080
    error: failed to discover supported resources: Get http://localhost:8080/apis/apps/v1?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
    Do you have any suggestions?

  5. Great article. Thanks for that. One thing though: when working with Ubuntu 18.04, I had to install CRI using the instructions at: https://kubernetes.io/docs/setup/production-environment/container-runtimes/

    And this action was taken because when minikube was started it output some warnings – one of which was this warning: [WARNING IsDockerSystemdCheck]: detected “cgroupfs” as the Docker cgroup driver. The recommended driver is “systemd”. Please follow the guide at https://kubernetes.io/docs/setup/cri/

  6. Getting this while executing with T2.micro, does this mean 1 CPU is not good enough handle this? please advise
    [[email protected] ~]$ minikube start –vm-driver=none
    😄 minikube v1.4.0 on Amazon 2018.03 (xen/amd64)
    💡 Requested CPU count 1 is less than the minimum allowed of 2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.