Minikube Essentials

The Minikube Essentials article provides you with a brief introduction to Minikube. It provides an installation guide and command-line commands to set up a local Kubernetes cluster on your local machine (macOS, Linux or Windows).
- What is minikube?
- Installation
- Minikube Configuration
- Minikube Usage Scenarios
- Minikube Commands
- Resources
The Minikube Essentials article provides you with a brief introduction to Minikube. It provides an installation guide and command-line commands to set up a local Kubernetes cluster on your local machine (macOS, Linux or Windows).
What is minikube?
Minikube creates a local Kubernetes cluster on macOS, Linux, and Windows. A production Kubernetes cluster setup consists of at least two master nodes and multiple worker nodes on separate virtual or physical machines. Minikube allows you to run a single-node Kubernetes cluster on your development machine. Both the master and worker processes are running on a single node. The docker runtime environment is pre-installed in the node.
Minikube supports Kubernetes features that makes sense locally like, DNS, NodePorts, PersistentVolumes, Ingress, ConfigMaps & Secrets, Dashboards, Container runtime (Docker, rkt, CRI-O), enabling CNI (Container Network Interface) and load balancer.
Minikube has several custom add-ons that can easily be enabled via the command line. The add-ons are dashboard, ingress, heapster, prometheus, registry-creds, and many more.
Installation
The following links contain guides on how to install minikube on your machine:
Minikube Configuration
The minikube deployment files in ~/.minikube/addons/deployment.yaml
can be used to run custom Kubernetes resources every time minikube starts.
Minikube is configurable via the config.json file, environment variables and flags. The $MINIKUBE_HOM
E resolves to the ~/.minikube
folder and contains all the minikube configuration and cached minikube artefacts.
Explicit Config: ~/.minikube/config/config.json
(Via minikube config set commands) Default Config: ~/.minikube/profiles/minikube/config.json
Applied Config: ~/.minikube/machines/minikube/config.json
Configuration files can be mounted on the minikube node via ~/.minikube/files/home/config.yaml -> /home/config.yaml
.
Minikube Usage Scenarios
Minikube Basic Startup
Start the local kubernetes cluster and ensure that minikube is up and running. Also ensure that all the pods are running as part of the minikube installation. Use the Kubernetes dashboard to see all the services are running, and finally stop the local kubernetes cluster.
# Starts a local Kubernetes cluster
$ minikube start
# List of each hypervisor instance that's running with hyperkit.
$ ps -ef | grep hyperkit
# List all pods across all namespaces in ps output format.
$ kubectl get pods --all-namespaces
# Access the Kubernetes dashboard running within the minikube cluster
$ minikube dashboard
# Stops the running local Kubernetes cluster
$ minikube stop
Deploy Application using a NodePort
Start the local kubernetes cluster and ensure that minikube is up and running. Also ensure that all the pods are running as part of the minikube installation. Create a deployment with the name application-nodeport
using the echoserver
image.
# Starts a local Kubernetes cluster
$ minikube start
# Create a deployment with the name application-nodeport using the echoserver image.
$ kubectl create deployment application-nodeport --image=k8s.gcr.io/echoserver:1.4
# List a specific deployment with the name application-nodeport
$ kubectl get deployment application-nodeport
# Show details of application-nodeport deployment
$ kubectl describe deployment application-nodeport
# Create a service object that exposes the deployment using the service type NodePort
$ kubectl expose deployment application-nodeport --type=NodePort --port=8080
# List a specific service with the name application-nodeport
$ kubectl get service application-nodeport
# Show details of application-nodeport service
$ kubectl describe service application-nodeport
# Option1: Launch the service and access the application via the default browser. (minikube launches browser)
$ minikube service application-nodeport
# Option 2: Use kubectl to forward the port and access application in browser at http://localhost:7080/
$ kubectl port-forward service/application-nodeport 7080:8080
# Access the Kubernetes dashboard running within the minikube cluster
$ minikube dashboard
# Delete the service called `application-nodeport`
$ kubectl delete service application-nodeport
# Delete the deployment called `application-nodeport`
$ kubectl delete deployment application-nodeport
# Stops the running local Kubernetes cluster
$ minikube stop
Deploy Application using a LoadBalancer
Start the local kubernetes cluster and ensure that minikube is up and running. Also ensure that all the pods are running as part of the minikube installation. Create a deployment with the name application-nodeport using the echoserver image.
# Starts a local Kubernetes cluster
$ minikube start
# Create a deployment with the name application-loadbalance using the echoserver image.
$ kubectl create deployment application-loadbalance --image=k8s.gcr.io/echoserver:1.4
# List a specific deployment with the name application-loadbalance
$ kubectl get deployment application-loadbalance
# Show details of application-loadbalance deployment
$ kubectl describe deployment application-loadbalance
# Create a service object that exposes the deployment using the service type LoadBalancer
$ kubectl expose deployment application-loadbalance --type=LoadBalancer --port=8080
# List a specific service with the name application-loadbalance
$ kubectl get service application-loadbalance
# Show details of application-loadbalance service
$ kubectl describe service application-loadbalance
# Option1: Launch the service and access the application via the default browser. (minikube launches browser)
$ minikube service application-loadbalance
# Option 2: Use kubectl to forward the port and access application in browser at http://localhost:7080/
$ kubectl port-forward service/application-loadbalance 7080:8080
# Access the Kubernetes dashboard running within the minikube cluster
$ minikube dashboard
# Delete the service called `application-loadbalance`
$ kubectl delete service application-loadbalance
# Delete the deployment called `application-loadbalance`
$ kubectl delete deployment application-loadbalance
# Stops the running local Kubernetes cluster
$ minikube stop
Minikube Logging & Debugging
# Starts a local Kubernetes cluster with log level verbosity of 0
$ minikube start --v=0
# Starts a local Kubernetes cluster with log level verbosity of 7 & log to standard error as well as files
$ minikube start --v=7 --alsologtostderr
# Gets the logs of the running instance, used for debugging minikube.
$ minikube logs
Gets the logs of the running instance, show only log entries which point to known problems
$ minikube logs --problems
# List all pods across all namespaces in ps output format.
$ kubectl get pods --all-namespaces
# Show detailed information about a po with a specific name and namespace.
$ kubectl describe pod <pod name> -n <namespace>
Minikube Commands
Minikube provisions and manages local Kubernetes clusters optimized for development workflows. The set of minikube commands were based minikube version: v1.17.1
.
Minikube Command Overview
This section contains a list of minikube commands that links to a set of examples and also to the official minikube documentation:
Basic Commands:
minikube start
- Starts a local Kubernetes cluster (Reference)minikube status
- Gets the status of a local Kubernetes cluster (Reference)minikube stop
- Stops a running local Kubernetes cluster (Reference)minikube delete
- Deletes a local Kubernetes cluster (Reference)minikube dashboard
- Access the Kubernetes dashboard running within the minikube cluster (Reference)minikube pause
- Pause Kubernetes (Reference)minikube unpause
- Unpause Kubernetes (Reference)
Images Commands:
minikube docker-env
- Configure environment to use minikube’s Docker daemon (Reference)minikube podman-env
- Configure environment to use minikube’s Podman service (Reference)minikube cache
- Add, delete, or push a local image into minikube (Reference)
Configuration and Management Commands:
minikube addons
- Enable or disable a minikube addon (Reference)minikube config
- Modify persistent configuration values (Reference)minikube profile
- Get or list the current profiles (clusters) (Reference)minikube update-context
- Update kubeconfig in case of an IP or port change (Reference)
Networking and Connectivity Commands:
minikube service
- Returns a URL to connect to a service (Reference)minikube tunnel
- Connect to LoadBalancer services (Reference)
Advanced Commands:
minikube mount
- Mounts the specified directory into minikube (Reference)minikube ssh
- Log into the minikube environment (for debugging) (Reference)minikube kubectl
- Run a kubectl binary matching the cluster version (Reference)minikube node
- Add, remove, or list additional nodes (Reference)
Troubleshooting Commands:
minikube ssh-key
- Retrieve the ssh identity key path of the specified cluster (Reference)minikube ip
- Retrieves the IP address of the running cluster (Reference)minikube logs
- Returns logs to debug a local Kubernetes cluster (Reference)minikube update-check
- Print current and latest version number (Reference)minikube version
- Print the version of minikube (Reference)
Other Commands:
minikube completion
- Generate command completion for a shell (Reference)minikube help
- Help about any command (Reference)minikube options
- Show a list of global command-line options (applies to all commands) (Reference)
Minikube Command Examples
# Lists all available minikube addons as well as their current statuses
$ minikube addons list
# Disables the addon `dashboard` within minikube.
$ minikube addons disable dashboard
# Enables the addon `dashboard` within minikube.
$ minikube addons enable dashboard
# Enables the addon `metrics-server` within minikube.
$ minikube addons enable metrics-server
# Open the dashboard addon in a browser, since it exposes a browser endpoint.
$ minikube addons open dashboard
Add, delete, or push a local image into minikube. See the ~/.minikube/cache/images
directory.
# List all the available images from the local cache.
$ minikube cache list
# Add the latest version of the nginx image to the local cache.
$ minikube cache add nginx:latest
# Reload the latest version of the nginx image to the local cache.
$ minikube cache reload nginx:latest
# Delete the latest vesrion of the nginx image from the local cache.
$ minikube cache delete nginx:latest
# Set the memory field to 16GB in the minikube config file (~/.minikube/config/config.json)
$ minikube config set memory 16384
# Display values currently set in the minikube config file (~/.minikube/config/config.json)
$ minikube config view
# Unsets the memory field in the minikube config file (~/.minikube/config/config.json)
$ minikube config unset memory
# Access the Kubernetes dashboard running within the minikube cluster
$ minikube dashboard
# Display dashboard URL instead of opening a browser
$ minikube dashboard --url
# Deletes a local Kubernetes cluster
$ minikube delete
# Deletes a local Kubernetes cluster & delete all profiles
$ minikube delete --all
# Deletes a local Kubernetes cluster & delete the '.minikube' folder from your user directory.
$ minikube delete --purge
# Retrieves the IP address of the running cluster, and writes it to STDOUT.
$ minikube ip
Use kubectl inside minikube
# Retrieve all the pods
$ minikube kubectl -- get pods
# Creating a deployment inside kubernetes cluster
$ minikube kubectl -- create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
# Exposing the deployment with a NodePort service
$ minikube kubectl -- expose deployment hello-minikube --type=NodePort --port=8080
# Display help
$ minikube kubectl -- --help
# Gets the logs of the running instance, used for debugging minikube, not user code.
$ minikube logs
# Display the logs of the running instance and continously print new entries
$ minikube logs -f
# Pause the Kubernetes cluster
$ minikube pause
# List the kubernetes URLs for the services in the local cluster. This is the same as `kubectl get svc -A`
$ minikube service list
# Starts a local Kubernetes cluster
$ minikube start
# Starts a local Kubernetes cluster with a profile name allowing multiple instances of minikube independently. (default "minikube")
$ minikube start --profile my-profile-name
# Starts a local kubernetes cluster and enable the metrics-server and dashboard addons at start-up.
$ minikube start --addons metrics-server --addons dashboard
# Starts a local kubernetes cluster with one of the drivers: virtualbox, parallels, vmwarefusion, hyperkit, vmware, docker, podman (experimental) (defaults to auto-detect)
$ minikube start --driver='hyperkit'
# Start a local kubernetes cluster in `debug` mode.
$ minikube start --v=7 --alsologtostderr
# Start a local kubernetes cluster and change the cluster version. (Supports any published Kubeadm build (>=1.8))
$ minikube start --kubernetes-version 1.16.1
# Start a local kubernetes cluster and choose a different container runtime (default:docker, cri-o, rkt)
$ minikube start --container-runtime=rkt
# Start a local kubernetes cluster and add configuration
$ minikube start --extra-config=kubelet.foo.bar=baz
# Gets the status of a local Kubernetes cluster.
$ minikube status
# Stops a local Kubernetes cluster. This command stops the underlying VM or container, but keeps user data intact.
$ minikube stop
# Unpause the Kubernetes cluster
$ minikube unpause
# Print current and latest version number of minikube
$ minikube update-check
# Print the version of minikube
$ minikube version
# Print the version of minikube in yaml format
$ minikube version --output='yaml'
# Print the version of minikube in json format
$ minikube version --output='json'