安装完毕后,如果我们也勾选了 Show system containers 选项,那么使用如下的 Docker 命令,能看到自动安装的 Kubernetes 相关容器:[如果下载失败、记得翻&墙哟]
下载完成后,可以查看容器:
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b309375c1719 registry.cn-qingdao.aliyuncs.com/charleslee1120/kubernetes-dashboard-amd64 "/dashboard --insecu…" 35 minutes ago Up 35 minutes k8s_kubernetes-dashboard_kubernetes-dashboard-5bd6f767c7-z7zqt_kube-system_1e83dd95-574a-11e8-9059-025000000001_0
f0a381160602 gcr.io/google_containers/pause-amd64:3.0 "/pause" About an hour ago Up About an hour k8s_POD_kubernetes-dashboard-5bd6f767c7-z7zqt_kube-system_1e83dd95-574a-11e8-9059-025000000001_0
6ec7eb1815df docker/kube-compose-api-server "/api-server --kubec…" 2 hours ago Up 2 hours k8s_compose_compose-api-7bb7b5968f-bgvz8_docker_ff60e14f-533c-11e8-bffe-025000000001_1
629af77e1b5c docker/kube-compose-controller "/compose-controller…" 2 hours ago Up 2 hours k8s_compose_compose-5d4f4d67b6-ttmpk_docker_ffa06241-533c-11e8-bffe-025000000001_0
7b7bc73c9b4d gcr.io/google_containers/k8s-dns-sidecar-amd64 "/sidecar --v=2 --lo…" 2 hours ago Up 2 hours k8s_sidecar_kube-dns-6f4fd4bdf-bxkgg_kube-system_dd401bc0-533c-11e8-bffe-025000000001_0
e8df8fbc0b78 gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 "/dnsmasq-nanny -v=2…" 2 hours ago Up 2 hours k8s_dnsmasq_kube-dns-6f4fd4bdf-bxkgg_kube-system_dd401bc0-533c-11e8-bffe-025000000001_0
9ebccac307d6 gcr.io/google_containers/k8s-dns-kube-dns-amd64 "/kube-dns --domain=…" 2 hours ago Up 2 hours k8s_kubedns_kube-dns-6f4fd4bdf-bxkgg_kube-system_dd401bc0-533c-11e8-bffe-025000000001_0
c5282fe45585 gcr.io/google_containers/kube-proxy-amd64 "/usr/local/bin/kube…" 2 hours ago Up 2 hours k8s_kube-proxy_kube-proxy-znhpr_kube-system_dd40eb4d-533c-11e8-bffe-025000000001_0
7d44d8a9be2b gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_compose-api-7bb7b5968f-bgvz8_docker_ff60e14f-533c-11e8-bffe-025000000001_0
a529d0c4af1e gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_compose-5d4f4d67b6-ttmpk_docker_ffa06241-533c-11e8-bffe-025000000001_0
23bfc8a97ee8 gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_kube-dns-6f4fd4bdf-bxkgg_kube-system_dd401bc0-533c-11e8-bffe-025000000001_0
5b016184998a gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_kube-proxy-znhpr_kube-system_dd40eb4d-533c-11e8-bffe-025000000001_0
c8dcb45da42b gcr.io/google_containers/kube-controller-manager-amd64 "kube-controller-man…" 2 hours ago Up 2 hours k8s_kube-controller-manager_kube-controller-manager-docker-for-desktop_kube-system_d0d736e78d128605e52b4714b87194e2_2
1ef8394a9996 gcr.io/google_containers/kube-scheduler-amd64 "kube-scheduler --le…" 2 hours ago Up 2 hours k8s_kube-scheduler_kube-scheduler-docker-for-desktop_kube-system_9ef17f6778a1c83c8484086fe563496a_1
e75037a33701 gcr.io/google_containers/kube-apiserver-amd64 "kube-apiserver --ad…" 2 hours ago Up 2 hours k8s_kube-apiserver_kube-apiserver-docker-for-desktop_kube-system_456d274175b3da6d378ff65feef4a86b_1
34f3513a02f4 gcr.io/google_containers/etcd-amd64 "etcd --listen-clien…" 2 hours ago Up 2 hours k8s_etcd_etcd-docker-for-desktop_kube-system_7278f85057e8bf5cb81c9f96d3b25320_1
b620faa00929 gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_kube-scheduler-docker-for-desktop_kube-system_9ef17f6778a1c83c8484086fe563496a_1
1130d71b5d1c gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_kube-controller-manager-docker-for-desktop_kube-system_d0d736e78d128605e52b4714b87194e2_1
1d9a857b0288 gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_kube-apiserver-docker-for-desktop_kube-system_456d274175b3da6d378ff65feef4a86b_1
a8411093a0a4 gcr.io/google_containers/pause-amd64:3.0 "/pause" 2 hours ago Up 2 hours k8s_POD_etcd-docker-for-desktop_kube-system_7278f85057e8bf5cb81c9f96d3b25320_4
shenhl:~ user$
docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest bfcb1f6df2db 12 days ago 107MB
gcr.io/google_containers/kube-apiserver-amd64 v1.9.6 a5c066e8c9bf 7 weeks ago 212MB
gcr.io/google_containers/kube-controller-manager-amd64 v1.9.6 472b6fcfe871 7 weeks ago 139MB
gcr.io/google_containers/kube-scheduler-amd64 v1.9.6 25d7b2c6f653 7 weeks ago 62.9MB
gcr.io/google_containers/kube-proxy-amd64 v1.9.6 70e63dd90b80 7 weeks ago 109MB
docker/kube-compose-controller v0.3.0-rc4 960fed8457c5 2 months ago 30.6MB
docker/kube-compose-api-server v0.3.0-rc4 adfd9ebd6d6d 2 months ago 43.8MB
k8s.gcr.io/kubernetes-dashboard-amd64 v1.8.3 0c60bcf89900 2 months ago 102MB
registry.cn-qingdao.aliyuncs.com/charleslee1120/kubernetes-dashboard-amd64 v1.8.3 0c60bcf89900 2 months ago 102MB
gcr.io/google_containers/etcd-amd64 3.1.11 59d36f27cceb 5 months ago 194MB
gcr.io/google_containers/k8s-dns-sidecar-amd64 1.14.7 db76ee297b85 6 months ago 42MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64 1.14.7 5d049a8c4eec 6 months ago 50.3MB
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64 1.14.7 5feec37454f4 6 months ago 41MB
gcr.io/google_containers/pause-amd64 3.0 99e59f495ffa 2 years ago 747kB
shenhl:~ user$
k8s.gcr.io/kubernetes-dashboard-amd64 需要单独下载,后面有讲解。
kubectl get pod
kubectl get pod --all-namespaces
kubectl describe pod
kubectl get pods --namespace kube-system
kubectl --namespace kube-system logs kubernetes-dashboard-5bd6f767c7-z7zqt
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
shenhl:~ user$ kubectl get pods --namespace kube-system
NAME READY STATUS RESTARTS AGE
etcd-docker-for-desktop 1/1 Running 1 5d
kube-apiserver-docker-for-desktop 1/1 Running 1 5d
kube-controller-manager-docker-for-desktop 1/1 Running 2 5d
kube-dns-6f4fd4bdf-bxkgg 3/3 Running 0 5d
kube-proxy-znhpr 1/1 Running 0 5d
kube-scheduler-docker-for-desktop 1/1 Running 1 5d
kubernetes-dashboard-5bd6f767c7-z7zqt
-如果出现pending,先找出问题,然后可以尝试将镜像单独拉取下来,方法如下:
-查看问题原因如下
kubectl --namespace kube-system logs kubernetes-dashboard-5bd6f767c7-z7zqt
-解决问题:将镜像单独拉取下来
docker pull registry.cn-qingdao.aliyuncs.com/charleslee1120/kubernetes-dashboard-amd64
docker tag registry.cn-qingdao.aliyuncs.com/charleslee1120/kubernetes-dashboard-amd64 k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dashboard
subjects:
- kind: ServiceAccount
name: dashboard
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
-然后执行安装(所建立的账号为dashboard):
kubectl create -f dashboard-rbac.yaml
--查看创建是否成功
kubectl get sa --all-namespaces
参考官方文档-详细介绍参见:https://github.com/kubernetes/dashboard/wiki/Creating-sample-user
-如果创建失败,如何删除如下:
kubectl delete sa/dashboard --namespace kube-system
kubectl delete clusterrolebindings/dashboard --namespace kube-system
--端口转发,外部可访问
kubectl port-forward kubernetes-dashboard-5bd6f767c7-z7zqt 8443:8443 --namespace=kube-system &
-- 内置服务,只能本机访问
kubectl proxy
-获取访问方式:
-- 访问时kubectl proxy命令一定要执行,不然访问不到了
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login
http://localhost:8001/ui
-获得登录授权码
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep dashboard | awk '{print $1}')
-运行结果如下[不要关闭,kubectl proxy ,记得打开,我实验时,就关闭了,最后又重启了下]:
-将上面的token内容拷贝下来,然后进入Web界面的 token ,复制到Enter Token下面的编辑框中