DEV Community

Steve Mak
Steve Mak

Posted on • Edited on

3 2

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

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay