minikube 安装 k8s

kubectl 安装

由于 API 版本兼容的问题,尽量保持 kubectl 版本与 K8S 集群版本保持一致,或版本相差在在一个小版本内

https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl

1
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/linux/amd64/kubectl

或者在 k8s github 地址 changelog 中下载

1
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.14.md

minikube 安装

官方下载地址:
https://github.com/kubernetes/minikube/releases

国内正常无法启动成功,因为它要从 gcr.io 拉取镜像, minikube 1.0.0 增加了 --image-repository 参数, 将此参数指定到阿里云即可。

安装方法:

1
minikube delete // 删除现有虚机,删除 ~/.minikube 目录缓存的文件

启动:

1
minikube start --vm-driver=none --registry-mirror=https://registry.docker-cn.com --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version v1.14.0

在 Linux 系统上面,将 Minikube 的 --vm-driver 参数设置为 none ,并且在本机已经正确安装 Docker,则无需虚拟化支持。

启动过程:

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
root@testminikube:~# minikube start --vm-driver=none --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers
o minikube v1.0.0 on linux (amd64)
$ Downloading Kubernetes v1.14.0 images in the background ...
> Creating none VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
2019/04/01 04:09:16 No matching credentials were found, falling back on anonymous
- "minikube" IP address is 192.168.3.18
- Configuring Docker as the container runtime ...
- Version of container runtime is 18.06.1-ce
: Waiting for image downloads to complete ...
- Preparing Kubernetes environment ...
- Pulling images required by Kubernetes v1.14.0 ...
- Launching Kubernetes v1.14.0 using kubeadm ...
: Waiting for pods: apiserver proxy etcd scheduler controller dns
- Configuring cluster permissions ...
- Verifying component health .....
> Configuring local host environment ...

! The 'none' driver provides limited isolation and may reduce system security and reliability.
! For more information, see:
- https://github.com/kubernetes/minikube/blob/master/docs/vmdriver-none.md

! kubectl and minikube configuration will be stored in /root
! To use kubectl or minikube commands as your own user, you may
! need to relocate them. For example, to overwrite your own settings:

- sudo mv /root/.kube /root/.minikube $HOME
- sudo chown -R $USER $HOME/.kube $HOME/.minikube

i This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
+ kubectl is now configured to use "minikube"
= Done! Thank you for using minikube!
root@testminikube:~# kubectl cluster-info
Kubernetes master is running at https://192.168.3.18:8443
KubeDNS is running at https://192.168.3.18:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

DNS 问题:

启动coreDNS 出错

debug地址 https://coredns.io/plugins/loop/

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
root@testminikube:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dc90838be2c1 eb516548c180 "/coredns -conf /etc…" 2 minutes ago Exited (1) 2 minutes ago k8s_coredns_coredns-d5947d4b-js28m_kube-system_f5c81728-544c-11e9-a910-000c295104be_12
a2d90e4b0c6b eb516548c180 "/coredns -conf /etc…" 2 minutes ago Exited (1) 2 minutes ago k8s_coredns_coredns-d5947d4b-4vz2j_kube-system_f5c50971-544c-11e9-a910-000c295104be_12
6e4be3a7474b 4689081edb10 "/storage-provisioner" 39 minutes ago Up 39 minutes k8s_storage-provisioner_storage-provisioner_kube-system_fe64bff1-544c-11e9-a910-000c295104be_0
59b80b5b458a registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 39 minutes ago Up 39 minutes k8s_POD_storage-provisioner_kube-system_fe64bff1-544c-11e9-a910-000c295104be_0
df5821598c5d 5cd54e388aba "/usr/local/bin/kube…" 39 minutes ago Up 39 minutes k8s_kube-proxy_kube-proxy-l9rpj_kube-system_f5c47051-544c-11e9-a910-000c295104be_0
60d7a877574d registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 39 minutes ago Up 39 minutes k8s_POD_coredns-d5947d4b-js28m_kube-system_f5c81728-544c-11e9-a910-000c295104be_0
cadbc4575d5c registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 39 minutes ago Up 39 minutes k8s_POD_coredns-d5947d4b-4vz2j_kube-system_f5c50971-544c-11e9-a910-000c295104be_0
186e88e78b9c registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 39 minutes ago Up 39 minutes k8s_POD_kube-proxy-l9rpj_kube-system_f5c47051-544c-11e9-a910-000c295104be_0
59104dbfe8cb ecf910f40d6e "kube-apiserver --ad…" 40 minutes ago Up 40 minutes k8s_kube-apiserver_kube-apiserver-minikube_kube-system_34d581cbe7724b7c44f1bcc01808ce2b_0
d4fe90aeab1c 2c4adeb21b4f "etcd --advertise-cl…" 40 minutes ago Up 40 minutes k8s_etcd_etcd-minikube_kube-system_0b2be8e1a0609d0edec7456c26d2017e_0
5fd380724605 119701e77cbc "/opt/kube-addons.sh" 40 minutes ago Up 40 minutes k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_6728e68c67451512f4a3f8ebf187f7c0_0
f2acdb49eb70 b95b1efa0436 "kube-controller-man…" 40 minutes ago Up 40 minutes k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_ad79208e444afcf9288f50 3469ee8a9f_0
4b8c04231fe4 00638a24688b "kube-scheduler --bi…" 40 minutes ago Up 40 minutes k8s_kube-scheduler_kube-scheduler-minikube_kube-system_6f3a3fe86a955711bb700f58d205f045_0
f439564293e3 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 40 minutes ago Up 40 minutes k8s_POD_kube-apiserver-minikube_kube-system_34d581cbe7724b7c44f1bcc01808ce2b_0
6837d66351dc registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 40 minutes ago Up 40 minutes k8s_POD_etcd-minikube_kube-system_0b2be8e1a0609d0edec7456c26d2017e_0
6a8bbf2adb23 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 40 minutes ago Up 40 minutes k8s_POD_kube-addon-manager-minikube_kube-system_6728e68c67451512f4a3f8ebf187f7c0_0
0fb3bcacb6e7 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 40 minutes ago Up 40 minutes k8s_POD_kube-scheduler-minikube_kube-system_6f3a3fe86a955711bb700f58d205f045_0
48a9f8539f78 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 40 minutes ago Up 40 minutes k8s_POD_kube-controller-manager-minikube_kube-system_ad79208e444afcf9288f503469ee8a9f_0
root@testminikube:~# docker logs dc90838be2c1
.:53
2019-04-01T07:45:24.546Z [INFO] CoreDNS-1.3.1
2019-04-01T07:45:24.546Z [INFO] linux/amd64, go1.11.4, 6b56a9c
CoreDNS-1.3.1
linux/amd64, go1.11.4, 6b56a9c
2019-04-01T07:45:24.546Z [INFO] plugin/reload: Running configuration MD5 = 599b9eb76b8c147408aed6a0bbe0f669
2019-04-01T07:45:24.547Z [FATAL] plugin/loop: Loop (127.0.0.1:36695 -> :53) detected for zone ".", see https://coredns.io/plugins/loop#troubleshooting. Query: "HINFO 1110760444785600987.5796964311732654450."

原因

https://coredns.io/plugins/loop/#troubleshooting

由于 ubuntu 系统将 namserver 设置为 127.0.0.53 导致此问题

解决:

1
2
3
systemctl disable systemd-resolved
vim /etc/resolvconf/resolv.conf.d/base
nameserver 8.8.8.8

存疑:

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
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c87d64f3d0c0 f9aed6605b81 "/dashboard --insecu…" 8 minutes ago Up 8 minutes k8s_kubernetes-dashboard_kubernetes-dashboard-9589d45df-zfmjf_kube-system_0eeb5738-5485-11e9-b716-08002761faf0_0
e6a18d854acc registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 8 minutes ago Up 8 minutes k8s_POD_kubernetes-dashboard-9589d45df-zfmjf_kube-system_0eeb5738-5485-11e9-b716-08002761faf0_0
e8c92c0f8637 eb516548c180 "/coredns -conf /etc…" 11 minutes ago Up 11 minutes k8s_coredns_coredns-d5947d4b-wwn57_kube-system_a39a6445-5484-11e9-b716-08002761faf0_2
5a49e2cb422b eb516548c180 "/coredns -conf /etc…" 11 minutes ago Up 11 minutes k8s_coredns_coredns-d5947d4b-bt7qr_kube-system_a399c170-5484-11e9-b716-08002761faf0_0
5509348a7611 4689081edb10 "/storage-provisioner" 11 minutes ago Up 11 minutes k8s_storage-provisioner_storage-provisioner_kube-system_a48d0d5a-5484-11e9-b716-08002761faf0_0
96689c775c18 eb516548c180 "/coredns -conf /etc…" 11 minutes ago Exited (2) 11 minutes ago k8s_coredns_coredns-d5947d4b-wwn57_kube-system_a39a6445-5484-11e9-b716-08002761faf0_1
9e2138641dbc registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 11 minutes ago Up 11 minutes k8s_POD_storage-provisioner_kube-system_a48d0d5a-5484-11e9-b716-08002761faf0_0
b2594dd49453 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 11 minutes ago Up 11 minutes k8s_POD_coredns-d5947d4b-bt7qr_kube-system_a399c170-5484-11e9-b716-08002761faf0_0
84b9556eddcd 5cd54e388aba "/usr/local/bin/kube…" 11 minutes ago Up 11 minutes k8s_kube-proxy_kube-proxy-rc8wh_kube-system_a3a0da36-5484-11e9-b716-08002761faf0_0
613ceec2b398 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 11 minutes ago Up 11 minutes k8s_POD_kube-proxy-rc8wh_kube-system_a3a0da36-5484-11e9-b716-08002761faf0_0
b1c59f3d3681 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 11 minutes ago Up 11 minutes k8s_POD_coredns-d5947d4b-wwn57_kube-system_a39a6445-5484-11e9-b716-08002761faf0_0
8f57f6f750f1 119701e77cbc "/opt/kube-addons.sh" 12 minutes ago Up 12 minutes k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_6728e68c67451512f4a3f8ebf187f7c0_0
ec8cd3584a87 b95b1efa0436 "kube-controller-man…" 12 minutes ago Up 12 minutes k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_81af92d0afc7c18b923d3c1cfeb25dde_0
54e552b6447a 00638a24688b "kube-scheduler --bi…" 12 minutes ago Up 12 minutes k8s_kube-scheduler_kube-scheduler-minikube_kube-system_6f3a3fe86a955711bb700f58d205f045_0
038a39ad50eb 2c4adeb21b4f "etcd --advertise-cl…" 12 minutes ago Up 12 minutes k8s_etcd_etcd-minikube_kube-system_fd5daa32004de0c636e0fe0efc91f2a7_0
dbfda924e721 ecf910f40d6e "kube-apiserver --ad…" 12 minutes ago Up 12 minutes k8s_kube-apiserver_kube-apiserver-minikube_kube-system_523956c1c877d6074e0ef2c35d1a3aa0_0
dc951ebb6bb6 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 12 minutes ago Up 12 minutes k8s_POD_kube-apiserver-minikube_kube-system_523956c1c877d6074e0ef2c35d1a3aa0_0
2936483c8f38 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 12 minutes ago Up 12 minutes k8s_POD_etcd-minikube_kube-system_fd5daa32004de0c636e0fe0efc91f2a7_0
b079ca751d3a registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 12 minutes ago Up 12 minutes k8s_POD_kube-addon-manager-minikube_kube-system_6728e68c67451512f4a3f8ebf187f7c0_0
491f459137e4 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 12 minutes ago Up 12 minutes k8s_POD_kube-scheduler-minikube_kube-system_6f3a3fe86a955711bb700f58d205f045_0
7eb83411c127 registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 "/pause" 12 minutes ago Up 12 minutes k8s_POD_kube-controller-manager-minikube_kube-system_81af92d0afc7c18b923d3c1cfeb25dde_0
$ docker logs 96689c775c18
E0401 13:47:09.340208 1 reflector.go:134] github.com/coredns/coredns/plugin/kubernetes/controller.go:322: Failed to list *v1.Namespace: Get https://10.96.0.1:443/api/v1/namespaces?limit=500&resourceVersion=0: tls: server selected unsupported protocol version 302
E0401 13:47:09.340208 1 reflector.go:134] github.com/coredns/coredns/plugin/kubernetes/controller.go:322: Failed to list *v1.Namespace: Get https://10.96.0.1:443/api/v1/namespaces?limit=500&resourceVersion=0: tls: server selected unsupported protocol version 302
log: exiting because of error: log: cannot create log: open /tmp/coredns.coredns-d5947d4b-wwn57.unknownuser.log.ERROR.20190401-134709.1: no such file or directory