loading...

Cheatsheet for Kubernetes (MiniKube & Kubectl)

ssmak profile image Steve Mak ・2 min read

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

Get the status

minikube status

Visit the dashboard

minikube dashboard

Stop a cluster

minikube stop

Delete a cluster

minikube delete

List available addons

minikube addons list

Enable an addon

minikube addons enable metrics-server

Disable an addon

minikube addons disable metrics-server

Proxy to a cluster service

minikube service <service_name>

Kubectl

Set the cluster configuration file that Kubectl should refer

kubectl config use-context minikube

Show the Kubernetes client and server versions

kubectl version

Create deployment

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

View deployments

kubectl get deployments

View pods

kubectl get pods

View services

kubectl get services

View pods and services

kubectl get pod,svc -n kube-system

View events

kubectl get events

View kubectl configuration

kubectl config view

Expose the pod to the public internet

kubectl expose deployment hello-node --type=LoadBalancer --port=8080

Delete the services

kubectl delete service hello-node

Delete the deployments

kubectl delete deployment hello-node

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

Discussion

pic
Editor guide