What Nick’s learning today: Install Kubernetes with Minikube

TL;DR> How to install Kubernetes using Minikube.  After reading this article you will be able to:

  • Download and install Minikube
  • Download and install the Kuberrnetes client, kubectl
  • Create a new Kubernetes cluster
  • Deploy a sample Kubernetes application

I’ve been using Kubernetes on my OpenStack cluster for some time now, so when I decided to test out its new installer, Helm, on my local machine, for my day job, I was at a bit of a loss. Fortunately, it turns out that installing Kubernetes can be a really fast and easy process.

The key is to use the official Minikube distribution. It may not be totally feature complete, but it’ll do for basic development work, and it’s under active development. Also installation seems to be fairly painless.  Follow these steps:

  1. Install Minikube: Download the latest version of Minikube.  At the time of this writing, that’s 0.17.1, available at https://github.com/kubernetes/minikube/releases/tag/v0.17.1. It’s available for MacOS, Linux, and Windows.  In this example, we’ll use MacOS, but the principles are the same.
    $ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.17.1/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 82.9M  100 82.9M    0     0  5204k      0  0:00:16  0:00:16 --:--:-- 6198k
    Password:
  2. Install the Kubernetes client. First download the software:
    $ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 47.7M  100 47.7M    0     0  4343k      0  0:00:11  0:00:11 --:--:-- 4654k
  3. Next, make kubectl executable:
    $ chmod +x ./kubectl
  4. Finally, move it to your path:
    $ sudo mv ./kubectl /usr/local/bin/kubectl
    Password:
  5. Now it’s time to start the cluster:
    $ minikube start
    Starting local Kubernetes cluster...
    Starting VM...
    SSH-ing files into VM...
    Setting up certs...
    Starting cluster components...
    Connecting to cluster...
    Setting up kubeconfig...
    Kubectl is now configured to use the cluster.
  6. We can test the cluster by creating a small sample deployment:
    $ kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
    deployment "hello-minikube" created
    
    $ kubectl expose deployment hello-minikube --type=NodePort
    service "hello-minikube" exposed
  7. Check to make sure that the container is actually running; the hello-minikube pod can take close to a minute to actually start:
    $ kubectl get pod
    NAME                                  READY     STATUS              RESTARTS   AGE
    hello-minikube-3015430129-43g6t       0/1       ContainerCreating   0          21s
    
    $ kubectl get pod
    NAME                                  READY     STATUS              RESTARTS   AGE
    hello-minikube-3015430129-43g6t       1/1       Running             0          40s
  8. Make a call to the service’s URL to make sure everything’s running smoothly.
    $ curl $(minikube service hello-minikube --url)
    CLIENT VALUES:
    client_address=172.17.0.1
    command=GET
    real path=/
    query=nil
    request_version=1.1
    request_uri=http://192.168.99.101:8080/
    
    SERVER VALUES:
    server_version=nginx: 1.10.0 - lua: 10001
    
    HEADERS RECEIVED:
    accept=*/*
    host=192.168.99.101:31881
    user-agent=curl/7.49.1
    BODY:
    -no body in request-

So at this point, you’re ready to run some Kubernetes apps.  More on that later.

Comments

Leave a Reply

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