DEV Community

Steve Mak
Steve Mak

Posted on • Edited on

Cheatsheet for Kubernetes (MiniKube & Kubectl)

MiniKube

Ref: https://kubernetes.io/docs/setup/learning-environment/minikube/

Start up a single node Kubernetes cluster

minikube start --kubernetes-version=<version> --driver=<driver_name>
------
e.g.
minikube start --kubernetes-version=v1.18.0 --driver=docker

Minikube supports the following drivers:
---
docker, virtualbox, podman, vmwarefusion, kvm2, hyperkit, hyperv, vmware, parallels, none
Enter fullscreen mode Exit fullscreen mode

Get the status

minikube status
Enter fullscreen mode Exit fullscreen mode

Visit the dashboard

minikube dashboard
Enter fullscreen mode Exit fullscreen mode

Stop a cluster

minikube stop
Enter fullscreen mode Exit fullscreen mode

Delete a cluster

minikube delete
Enter fullscreen mode Exit fullscreen mode

List available addons

minikube addons list
Enter fullscreen mode Exit fullscreen mode

Enable an addon

minikube addons enable metrics-server
Enter fullscreen mode Exit fullscreen mode

Disable an addon

minikube addons disable metrics-server
Enter fullscreen mode Exit fullscreen mode

Proxy to a cluster service

minikube service <service_name>
Enter fullscreen mode Exit fullscreen mode

Kubectl

Set the cluster configuration file that Kubectl should refer

kubectl config use-context minikube
Enter fullscreen mode Exit fullscreen mode

Show the Kubernetes client and server versions

kubectl version
Enter fullscreen mode Exit fullscreen mode

Create deployment

kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
Enter fullscreen mode Exit fullscreen mode

View deployments

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

View pods

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

View services

kubectl get services
Enter fullscreen mode Exit fullscreen mode

View pods and services

kubectl get pod,svc -n kube-system
Enter fullscreen mode Exit fullscreen mode

View events

kubectl get events
Enter fullscreen mode Exit fullscreen mode

View kubectl configuration

kubectl config view
Enter fullscreen mode Exit fullscreen mode

Expose the pod to the public internet

kubectl expose deployment hello-node --type=LoadBalancer --port=8080
Enter fullscreen mode Exit fullscreen mode

Delete the services

kubectl delete service hello-node
Enter fullscreen mode Exit fullscreen mode

Delete the deployments

kubectl delete deployment hello-node
Enter fullscreen mode Exit fullscreen mode

YAML Reference

Deployment

Example 1

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-web
  labels:
    app: helloworld-web
    tier: frontend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: helloworld-web
      tier: frontend
  template:
    metadata:
      labels:
        app: helloworld-web
        tier: frontend
    spec:
      containers:
      - name: helloworld-web
        image: ssmak/helloworld_web:latest
        ports:
        - containerPort: 80
        - containerPort: 443
Enter fullscreen mode Exit fullscreen mode

Top comments (0)