赞
踩
- apiVersion: v1
- kind: ServiceAccount
- metadata:
- labels:
- k8s-app: kubernetes-dashboard
- addonmanager.kubernetes.io/mode: Reconcile
- name: kubernetes-dashboard
- namespace: kube-system
- ---
- apiVersion: apps/v1beta2
- kind: Deployment
- metadata:
- name: kubernetes-dashboard
- namespace: kube-system
- labels:
- k8s-app: kubernetes-dashboard
- kubernetes.io/cluster-service: "true"
- addonmanager.kubernetes.io/mode: Reconcile
- spec:
- selector:
- matchLabels:
- k8s-app: kubernetes-dashboard
- template:
- metadata:
- labels:
- k8s-app: kubernetes-dashboard
- annotations:
- scheduler.alpha.kubernetes.io/critical-pod: ''
- spec:
- serviceAccountName: kubernetes-dashboard
- containers:
- - name: kubernetes-dashboard
- image: 10.0.11.222:5000/bigdata/kubernetes-dashboard-amd64:v1.8.0
- resources:
- limits:
- cpu: 100m
- memory: 300Mi
- requests:
- cpu: 100m
- memory: 100Mi
- ports:
- - containerPort: 8443
- protocol: TCP
- args:
- - --auto-generate-certificates
- volumeMounts:
- - name: kubernetes-dashboard-certs
- mountPath: /certs
- - name: tmp-volume
- mountPath: /tmp
- livenessProbe:
- httpGet:
- scheme: HTTPS
- path: /
- port: 8443
- initialDelaySeconds: 30
- timeoutSeconds: 30
- volumes:
- - name: kubernetes-dashboard-certs
- secret:
- secretName: kubernetes-dashboard-certs
- - name: tmp-volume
- emptyDir: {}
- serviceAccountName: kubernetes-dashboard
- tolerations:
- - key: "CriticalAddonsOnly"
- operator: "Exists"
- ---
- apiVersion: v1
- kind: Service
- metadata:
- name: kubernetes-dashboard
- namespace: kube-system
- labels:
- k8s-app: kubernetes-dashboard
- kubernetes.io/cluster-service: "true"
- addonmanager.kubernetes.io/mode: Reconcile
- spec:
- type: NodePort
- selector:
- k8s-app: kubernetes-dashboard
- ports:
- - port: 443
- targetPort: 8443
spec.containers.image
:填写dashboard
的镜像路径。我这里填写的是本地私有库的dashboard
镜像。大家可以通过docker search
查询1.8.0版本
的dashboard
。
spec.containers.args
:此处填写的是一些参数,由于我的kubernetes1.8.0
是通过HTTPS
安全验证的安装,访问的是http://masterip:6443
,因此,此处我填写了- --auto-generate-certificates
,用以自动生成dashboard证书,此处不需要填写apiserver
地址。
因为kubernetes1.8.0
开启了 RBAC
所以这里需要创建一个 RBAC
认证。
- apiVersion: v1
- kind: ServiceAccount
- metadata:
- name: kubernetes-dashboard
- namespace: kube-system
-
- ---
-
- kind: ClusterRoleBinding
- apiVersion: rbac.authorization.k8s.io/v1beta1
- metadata:
- name: kubernetes-dashboard
- subjects:
- - kind: ServiceAccount
- name: kubernetes-dashboard
- namespace: kube-system
- roleRef:
- kind: ClusterRole
- name: cluster-admin
- apiGroup: rbac.authorization.k8s.io
新建一个空目录:certs
,然后执行下面命令:
kubectl create secret generic kubernetes-dashboard-certs --from-file=certs -n kube-system
将上面两个文件kubernetes-dashboard.yaml
、kubernetes-rbac.yaml
放置到同一个目录,该目录只要这两个文件,然后执行下面的命令:
- # 读取当前目录配置文件进行安装启动
- kubectl apply -f .
查看namespace
为kube-system
下的pod
- kubectl get pods --namespace="kube-system"
-
-
- NAME READY STATUS RESTARTS AGE
- kubernetes-dashboard-77bd6c79b-sc5wb 1/1 Running 1 56m
pods/
后面跟指定pod
name
kubectl describe pods/kubernetes-dashboard-77bd6c79b-sc5wb --namespace="kube-system"
由于详情过多,此处截图只展示部分信息:
访问以下链接(1.8.0访问 https://masterip:6443/ui 无法访问):
https://MasterIP:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
MasterIP
:kubernetes
集群master
节点ip
kubernetes-dashboard
界面:
首次安装,如果没有做apiserver
参数配置,则可能会出现一些问题。下面就看下常见问题的解决方法
访问dashboard
网页时,可能出现下面这种报错:
- {
- "kind": "Status",
- "apiVersion": "v1",
- "metadata": {
-
- },
- "status": "Failure",
- "message": "services \"https:kubernetes-dashboard:\" is forbidden: User \"system:anonymous\" cannot get services/proxy in the namespace \"kube-system\"",
- "reason": "Forbidden",
- "details": {
- "name": "https:kubernetes-dashboard:",
- "kind": "services"
- },
- "code": 403
- }
Kubernetes API Server
新增了–anonymous-auth
选项,允许匿名请求访问secure port
。没有被其他authentication
方法拒绝的请求即Anonymous requests
, 这样的匿名请求的username
为system:anonymous
, 归属的组为system:unauthenticated
。并且该选线是默认的。这样一来,当采用chrome
浏览器访问dashboard UI
时很可能无法弹出用户名、密码输入对话框,导致后续authorization
失败。为了保证用户名、密码输入对话框的弹出,需要将–anonymous-auth
设置为false
。
解决方法:
在api-server
配置文件中添加--anonymous-auth=false
- vi /etc/systemd/system/kube-apiserver.service
-
- [Unit]
- Description=Kubernetes API Server
- Documentation=https://github.com/GoogleCloudPlatform/kubernetes
- After=network.target
-
- [Service]
- User=root
- ExecStart=/usr/local/bin/kube-apiserver \
- --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,NodeRestriction \
- --advertise-address=10.0.11.222 \
- --allow-privileged=true \
- --apiserver-count=3 \
- --audit-policy-file=/etc/kubernetes/audit-policy.yaml \
- --audit-log-maxage=30 \
- --audit-log-maxbackup=3 \
- --audit-log-maxsize=100 \
- --audit-log-path=/var/log/kubernetes/audit.log \
- --authorization-mode=Node,RBAC \
- --anonymous-auth=false \ # 不接受匿名访问,若为true,则表示接受,此处设置为false,便于dashboard访问
- --bind-address=0.0.0.0 \
- --secure-port=6443 \
- --client-ca-file=/etc/kubernetes/ssl/ca.pem \
- --enable-swagger-ui=true \
- --etcd-cafile=/etc/kubernetes/ssl/ca.pem \
- --etcd-certfile=/etc/kubernetes/ssl/etcd.pem \
- --etcd-keyfile=/etc/kubernetes/ssl/etcd-key.pem \
- --etcd-servers=https://10.0.11.222:2379 \
- --event-ttl=1h \
- --kubelet-https=true \
- --insecure-bind-address=127.0.0.1 \
- --insecure-port=8080 \
- --service-account-key-file=/etc/kubernetes/ssl/ca-key.pem \
- --service-cluster-ip-range=10.254.0.0/16 \
- --service-node-port-range=30000-32000 \
- --tls-cert-file=/etc/kubernetes/ssl/kubernetes.pem \
- --tls-private-key-file=/etc/kubernetes/ssl/kubernetes-key.pem \
- --enable-bootstrap-token-auth \
- --token-auth-file=/etc/kubernetes/token.csv \
- --v=2
- Restart=on-failure
- RestartSec=5
- Type=notify
- LimitNOFILE=65536
-
- [Install]
- WantedBy=multi-user.target
解决了上面那个问题之后,再度访问dashboard
页面,发现还是有问题,出现下面这个问题:
- {
- "kind": "Status",
- "apiVersion": "v1",
- "metadata": {
-
- },
- "status": "Failure",
- "message": "Unauthorized",
- "reason": "Unauthorized",
- "code": 401
- }
解决方法:
新建/etc/kubernetes/basic_auth_file
文件,并在其中添加:
admin,admin,1002
文件内容格式:password,username,uid
然后在api-server
配置文件(即上面的配置文件)中添加--basic-auth-file=/etc/kubernetes/basic_auth_file \
保存重启kube-apiserver
:
- systemctl daemon-reload
- systemctl enable kube-apiserver
- systemctl start kube-apiserver
- systemctl status kube-apiserver
最后在kubernetes上执行下面这条命令:
kubectl create clusterrolebinding login-dashboard-admin --clusterrole=cluster-admin --user=admin
将访问账号名admin
与kubernetes-rbac.yaml
文件中指定的cluster-admin
关联,获得访问权限。
如果安装的docker
版本为1.13
及以上,并且网络畅通,flannel
、etcd
都正常,但还是会出现getsockopt: connection timed out'
的错误,则可能是iptables
配置问题。具体问题:
Error: 'dial tcp 10.233.50.3:8443: getsockopt: connection timed out
docker
从1.13
版本开始,可能将iptables FORWARD chain
的默认策略设置为DROP
,从而导致ping
其他Node上
的Pod IP
失败,遇到这种问题时,需要手动设置策略为ACCEPT
:
sudo iptables -P FORWARD ACCEPT
使用iptables -nL
命令查看,发现Forward
的策略还是drop
,可是我们明明执行了iptables -P FORWARD ACCEPT
。原来,docker
是在这句话执行之后启动的,需要每次在docker
之后再执行这句话。。。这么做有点太麻烦了,所以我们修改下docker
的启动脚本:
- vi /usr/lib/systemd/system/docker.service
-
-
- [Service]
- Type=notify
- # the default is not to use systemd for cgroups because the delegate issues still
- # exists and systemd currently does not support the cgroup feature set required
- # for containers run by docker
-
- ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS $DOCKER_OPTS $DOCKER_DNS_OPTIONS
-
- # 添加这行操作,在每次重启docker之前都会设置iptables策略为ACCEPT
- ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
-
- ExecReload=/bin/kill -s HUP $MAINPID
在启动文件中的 [Service]
下添加一行配置,即上面代码中的配置即可。
然后重启docker
,再次查看dashboard
网页。
参考文章:
1. 解决Kubernetes 1.6.4 Dashboard无法访问的问题
2. Kubernetes集群Dashboard插件安装
3. 解决Centos7下Kubernetes(k8s)部署好之后无法访问dashboard
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。