k8s集群搭建(三)

时间:2021-05-23 10:45:14

Dashboard安装

Kubernetes Dashboard是k8s提供基于Web的监控和操作界面,可以通过UI来显示集群的所有工作负载,除了查看资源,还是创建、编辑、更新、删除资源。

根据Kubernetes Dashboard的github上提供的样例编写kubernate-dashboard.yml文件,内容如下:

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
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
app: kubernetes-dashboard
template:
metadata:
labels:
app: kubernetes-dashboard
spec:
containers:
- name: kubernetes-dashboard
# gcr.io需要* 这里找的第三方的服务
image: myhub.fdccloud.com/library/kubernetes-dashboard-amd64:v1.5.1
imagePullPolicy: Always
ports:
- containerPort: 9090
protocol: TCP
volumeMounts:
- name: "kubeconfig"
mountPath: "/etc/kubernetes/"
readOnly: true
args:
#增加的配置
- --apiserver-host=http://master:8080
livenessProbe:
httpGet:
path: /
port: 9090
initialDelaySeconds: 30
timeoutSeconds: 30
volumes:
- name: "kubeconfig"
hostPath:
path: "/etc/kubernetes/"
---
kind: Service
ap 大专栏  k8s集群搭建(三)iVersion: v1
metadata:
labels:
app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
type: NodePort
ports:
- port: 80
targetPort: 9090
selector:
app: kubernetes-dashboard

执行下面命令,创建并启动dashboard

1
$ kubectl create -f kubernete-dashboard.yml

通过下面命令查看是否成功

1
$ kubectl get pod --namespace=kube-system

在国内没有*的情况下,这个pod的status会卡在ContainerCreating,

通过下面命令查看具体情况

1
$ kubectl describe pod kubernetes-dashboard --namespace=kube-system

可以看到下面的出错信息

1
2
Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for gcr.io/google_containers/pause-amd64:3.0, this may be because there are no credentials on this request.  details: (Error response from daemon: Get https://gcr.io/v1/_ping: dial tcp 64.233.187.82:443: i/o timeout)"
Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image "gcr.io/google_containers/pause-amd64:3.0""

这是因为kubernetes在创建pod的时候,需要从gcr.io下载pause-amd64镜像,作为pod的网络接入点。

但是目前国内无法访问gcr.io,这个问题会导致无法下载该镜像,然后Pod一直处于ContainerCreating状态。

那这里就在集群的node节点上都通过阿里云的镜像来pull镜像

1
2
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0
docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0

然后重新创建pod

1
2
$ kubectl delete -f kubernete-dashboard.yml  //先删除失败的pod
$ kubectl create -f kubernete-dashboard.yml

在此通过kubectl get pod –namespace=kube-system查看pod状态应该是running了,表示成功

这个时候在浏览器通过http://172.16.110.108:8080/ui会自动跳转到http://172.16.110.108:8080/api/v1/proxy/namespaces/kube-system/services/kube-ui/#/dashboard/即可访问kebe-ui的dashboard的页面,但是这时候我又遇到了一个问题提示flannel的网络无法访问,这是因为我之前master上没有安装配置flannel,所以kube-apiserver无法访问dashboard的pod

参考前面的flannel的安装配置,在master也安装配置flannel,重启kube-apiserver只有就可以访问。不过我是在重启master之后才可以访问的。