Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Install Minikube with virtual-box VM driver

$ brew update && brew install kubectl && brew cask install docker minikube virtualbox
$ brew cask reinstall minikube
$ minikube delete
$ rm -fr ~/.minikube/

Flag --vm-driver=xxx

* virtualbox
* vmwarefusion
* kvm2
* kvm 
* hyperkit 

We can change the minikube config with config command

$ minikube config set memory 8192
$ minikube config set cpus 4
$ minikube config set vm-drive vmwarefusion 
$ minikube config view

You can directly pass the memory and CPU options to the minikube start command like:

$ minikube start --memory 8192 --cpus 4
$ minikube config view
    - WantReportError: true
    - cpus: 4
    - ingress: true
    - memory: 8192

Start minikube on virtualbox

$ minikube start --vm-driver virtualbox

Start minikube with hyperkit, The best for macOS

$ minikube start --vm-driver hyperkit --memory 8192 --cpus 2

You can supply the kubernetes version you want minikube to start by mentioning the --kubernetes-version

$ minikube start --kubernetes-version v1.13.0    

Minikube configuration

$ cat ~/.minikube/machines/minikube/config.json

ssh minikube VM

$ ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip)
$ ssh minikube

Setup docker to talk to minikube , command to use Minikube Docker daemon

$ minikube docker-env
    export DOCKER_TLS_VERIFY="1"
    export DOCKER_HOST="tcp://192.168.64.7:2376"
    export DOCKER_CERT_PATH="/Users/Username/.minikube/certs"
    export DOCKER_API_VERSION="1.35"
        # Run this command to configure your shell:
        # eval $(minikube docker-env)

Build an image from a Dockerfile and deploye on minikube

$ cd /Users/rcherara/Projects-Minikube/rcherara-api-book/
$ docker build --file=Dockerfile --tag=rcherara-api-book:latest --rm=true
$ kubectl run rcherara-api-book --image=rcherara-api-book:latest --port=7680 --image-pull-policy Never

You can switch from local (minikube) to gcloud and back with:

$ kubectl config use-context CONTEXT_NAME
$ kubectl config use-context minikube
# for more info https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

To list all cotexts:

$ kubectl config get-contexts

View the Pod and Service you just created:

$ kubectl get pod,svc -n kube-system

Setup docker to talk to minikube , command to use Minikube Docker daemon

$ minikube docker-env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.64.7:2376" export DOCKER_CERT_PATH="/Users/Username/.minikube/certs" export DOCKER_API_VERSION="1.35" # Run this command to configure your shell: # eval $(minikube docker-env)

Minikube Logs

$ minikube logs

Node and cluster info

$ kubectl describe nodes
$ kubectl cluster-info

Dashboard

$ minikube dashboard

Services

$ minikube service [-n NAMESPACE] [--url] NAME

Enable ingress

$ minikube addons enable ingress

Show minikube cluster IP

$ minikube ip

Deploy and expose Hello minikupe

$ kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
$ kubectl expose deployment hello-minikube --type=NodePort

We have now launched an echoserver pod but we have to wait until the pod is up before curling/accessing it via the exposed service.

To check whether the pod is up and running

$ kubectl get pod

See that the pod is now Running and we will now be able to curl it:

$ curl $(minikube service hello-minikube --url)

To create new namespace

$ kubectl create namespace rcherara

Deployment

$ kubectl run my-nginx --image=nginx --port=80
$ kubectl expose deployment my-nginx --type=NodePort 
$ Kubectl scale --replicas=3 deployment/my-nginx

Stopping a Cluster Minikube

$ minikube stop

This command shuts down the Minikube Virtual Machine, but preserves all cluster state and data. Starting the cluster again will restore it to it’s previous state

Install helm on the cluster

Helm is a tool that streamlines installing and managing Kubernetes applications. Think of it like apt/yum/homebrew for Kubernetes.

$ brew install kubernetes-helm
$ helm init
$ helm repo update 

$ helm install stable/drupal
$ helm install stable/wordpress
$ helm install --name my-release stable/jenkins

cert-manager

$ helm install
--name cert-manager
--namespace kube-system
stable/cert-manager

Note : If your cluster does not use RBAC (Role Based Access Control), you will need to disable creation of RBAC resources by adding --set rbac.create=false to your helm install command above.

Helmfile configuration management.

$ curl -L -o ~/bin/helmfile https://github.com/roboll/helmfile/releases/download/v0.17.0/helmfile_darwin_amd64
$ chmod +x ~/bin/helmfile

See Also

Minikube documentation at : https://kubernetes.io/docs/getting-started-guides/minikube/

minikube source on GitHub : https://github.com/kubernetes/minikube
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment