-
Notifications
You must be signed in to change notification settings - Fork 29
Minikube
The simplest and quickest way to get started with Kubernetes is to install Minikube on your local machine. Minikube is a tool that sets up a single-node cluster that's great for both testing Kubernetes and developing apps locally.
Since Minikube is running locally instead of on a cloud provider, certain provider-specific features like LoadBalancers and PersistentVolumes will not work out-of-the-box. However, you can use NodePort LoadBalancers and HostPath PersistentVolumes.
NOTE Minikube doesn't support LoadBalancer
services, so the service will never get an external IP. But you get the IP and port through which you can access service by running minikube service kubia-http
.
- Before you begin
- Prerequisite
- Verify the Installation
- Start Minikube
- Check k8s
- Use minikube's built-in docker daemon
- Build, deploy and run an image on your local k8s setup
- Minikube Cheat Sheet
- Dashboard
- Minikube Add-ons
- Minikube config
- Delete deployment of my-app
- Reset everything
Minikube requires that VT-x/AMD-v virtualization is enabled in BIOS. To check that this is enabled on OSX / macOS run:
sysctl -a | grep machdep.cpu.features | grep VMX
If there's output, you're good!
- kubectl
- docker (for Mac)
- minikube
- virtualbox
The best way to get started on a macOS is to use Homebrew. If you already have Homebrew installed, you can install kubectl
, docker
, minikube
, and virtualbox
by running the following command
brew update && brew install kubectl && brew cask install docker minikube virtualbox
If you don't already have Homebrew installed, I would strongly recommend that you install it! It's incredibly useful for installing software dependencies like OpenSSL, MySQL, Postgres, Redis, SQLite, and more.
You can install it by running the following command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
docker --version # Docker version 17.09.0-ce, build afdb6d4
docker-compose --version # docker-compose version 1.16.1, build 6d1ac21
docker-machine --version # docker-machine version 0.12.2, build 9371605
minikube version # minikube version: v0.22.3
kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1",
GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"}
minikube start
This can take a while, expected output:
Starting local Kubernetes cluster...
Kubectl is now configured to use the cluster.
Great! You now have a running Kubernetes cluster locally. Minikube started a virtual machine for you, and a Kubernetes cluster is now running in that VM.
kubectl get nodes
Should output something like:
NAME STATUS ROLES AGE VERSION
minikube Ready <none> 40s v1.7.5
eval $(minikube docker-env)
Running docker ps
should now output something like:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e97128790bf9 gcr.io/google-containers/kube-addon-manager "/opt/kube-addons.sh" 22 seconds ago Up 22 seconds k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0
69707e54d1d0 gcr.io/google_containers/pause-amd64:3.0 "/pause" 33 seconds ago Up 33 seconds k8s_POD_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0
First setup a local registry, so Kubernetes can pull the image(s) from there:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
First of, store all files (Dockerfile, my-app.yml, index.html) in this gist locally in some new (empty) directory.
You can build the Dockerfile below locally if you want to follow this guide to the letter. Store the Dockerfile locally, preferably in an empty directory and run:
docker build . --tag my-app
You should now have an image named 'my-app' locally, check by using docker images
(or your own image of course). You can then publish it to your local docker registry:
docker tag my-app localhost:5000/my-app:0.1.0
Running docker images
should now output the following:
REPOSITORY TAG IMAGE ID CREATED SIZE
my-app latest cc949ad8c8d3 44 seconds ago 89.3MB
localhost:5000/my-app 0.1.0 cc949ad8c8d3 44 seconds ago 89.3MB
httpd 2.4-alpine fe26194c0b94 7 days ago 89.3MB
Store the file below my-app.yml
on your system and run the following:
kubectl create -f my-app.yml
You should now see your pod and your service:
kubectl get all
The configuration exposes my-app
outside of the cluster, you can get the address to access it by running:
minikube service my-app --url
This should give an output like http://192.168.99.100:30304
(the port will most likely differ). Go there with your favorite browser, you should see "Hello world!". You just accessed your application from outside of your local Kubernetes cluster!
To open the dashboard in your browser when using Minikube to run your Kubernetes cluster, run the following command:
$ minikube dashboard
The dashboard will open in your default browser. Unlike with GKE, you won’t need to enter any credentials to access it.
Minikube starts with some default VM configs for any modern machine.
DefaultMemory = 2048
DefaultCPUS = 2
DefaultDiskSize = "20g"
MinimumDiskSizeMB = 2000
DefaultVMDriver = "virtualbox"
Which is fine for most of the time. But for various reasons, the defaults may not be what one needs. The VM configs can be overridden by passing flags like:
$ minikube stop && minikube start --cpus 4 --memory 8192
But let’s say, we are constrained by memory on the system and missing the flag could result in freezing the whole system due to a 2GB memory VM. To avoid this, minikube config file can be set to override the defaults all the time. The config file is located at ~/.minikube/config/config.json
, until explicitly changed. The config can be used to enable/disable k8s add-ons and set various parameter values for the setup.
To get the names of the configurable fields, run minikube config -h
.
Configurable fields:
- vm-driver
- v
- cpus
- disk-size
- host-only-cidr
- memory
- log_dir
- kubernetes-version
- iso-url
- WantUpdateNotification
- ReminderWaitPeriodInHours
- WantReportError
- WantReportErrorPrompt
- WantKubectlDownloadMsg
- profile
- dashboard
- addon-manager
- default-storageclass
- kube-dns
- heapster
- ingress
- registry
- registry-creds
- default-storageclass
- hyperv-virtual-switch
- disable-driver-mounts
That’s the configurable fields at the time of writing this post. minikube config
command lets you change the config without manually editing the config file.
$ minikube config set memory 1024
$ minikube config set disk-size 2000MB
kubectl delete deploy my-app
kubectl delete service my-app
You're now good to go and deploy other images!
minikube stop;
minikube delete;
rm -rf ~/.minikube .kube;
brew uninstall kubectl;
brew cask uninstall docker virtualbox minikube;
Last tested on 2017 October 20th macOS Sierra 10.12.6