k8s_minikube

minikube

There are several tools to setup Vanilla Kubernetes, like kubeadm, minikube, Kubespray, while minikube is to setup Vanilla Kubernetes locally, focusing on making it easy to learn and develop for Kubernetes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# start k8s cluster
$ minikube start
# for china use this one
$ sudo minikube start --driver=none --extra-config=kubeadm.ignore-preflight-errors=NumCPU --force --image-mirror-country=cn

$ minikube pause
$ minikube stop

$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
timeToStop: Nonexistent

$ minikube delete --all

$ minikube addons list

# enable ingress plugin
$ minikube addons enable ingress
The 'ingress' addon is enabled.

# after ingress is enabled, an ingress pod is running listen on 80 by nginx
# and meanwhile docker-proxy starts as well on the node which ingress pod runs.
# so that if you access that node on port 80, it will proxy the traffic to ingress container
# which performs ingress rules and selects the proper endpoint

root 10678 1009 0 Jun30 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 80 -container-ip 172.17.0.6 -container-port 80


$ kubectl cluster-info
Kubernetes control plane is running at https://10.116.5.201:8443
KubeDNS is running at https://10.116.5.201:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
# after cluster starts, check or deploy pod, service
$ kubectl get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-54d67798b7-f6wq8 1/1 Running 0 11h
kube-system etcd-dev 1/1 Running 0 11h
kube-system kube-apiserver-dev 1/1 Running 0 11h
kube-system kube-controller-manager-dev 1/1 Running 0 11h
kube-system kube-proxy-fsd9r 1/1 Running 0 11h
kube-system kube-scheduler-dev 1/1 Running 0 11h
kube-system storage-provisioner 0/1 ImagePullBackOff 0 11h


# Create a sample deployment and expose it on port 8080:
$ kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
$ kubectl expose deployment hello-minikube --type=NodePort --port=8080

# check service
$ kubectl get services hello-minikube

# map to host port 7080
$ kubectl port-forward service/hello-minikube 7080:8080
$ curl http://localhost:7080/

troubleshooting

dashboard is not working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# run minikube command with more logs for troubleshooting
$ minikube addons enable dashboard
$ minikube addons enable metrics-server
# if pod is not ready due to pull image error like this
$ kubectl get po -n kubernetes-dashboard --show-labels
NAME READY STATUS RESTARTS AGE LABELS
dashboard-metrics-scraper-8554f74445-rnq6d 0/1 ImagePullBackOff 0 15m k8s-app=dashboard-metrics-scraper,pod-template-hash=8554f74445
kubernetes-dashboard-6c87f58d7c-48gk7 0/1 ImagePullBackOff 0 15m gcp-auth-skip-secret=true,k8s-app=kubernetes-dashboard,pod-template-hash=6c87f58d7c

# change the image for these pods
# registry.cn-hangzhou.aliyuncs.com/lxm-k8s/metrics-scraper:v1.0.6
# registry.cn-hangzhou.aliyuncs.com/lixunan/kubernetes-dashboard:v2.1.0
$ sudo kubectl set image deploy kubernetes-dashboard kubernetes-dashboard=registry.cn-hangzhou.aliyuncs.com/lixunan/kubernetes-dashboard:v2.1.0 -n kubernetes-dashboard

$ sudo kubectl set image deploy dashboard-metrics-scraper dashboard-metrics-scraper=registry.cn-hangzhou.aliyuncs.com/lxm-k8s/metrics-scraper:v1.0.6 -n kubernetes-dashboard

# local access from this machine
$ minikube dashboard
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
http://127.0.0.1:43909/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

# remote access by proxy, all interfaces
$ sudo kubectl proxy --address='0.0.0.0' --disable-filter=true
# http://10.117.5.21:8001/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/overview?namespace=default

$ kubectl get po -n kubernetes-dashboard --show-labels
$ kubectl describe po -l k8s-app=kubernetes-dashboard -n kubernetes-dashboard
$ kubectl logs -l k8s-app=kubernetes-dashboard -n kubernetes-dashboard

Ref