当前位置:   article > 正文

Kubernetes dashboard1.8.0 WebUI安装与配置_anonymous-auth在哪里配置

anonymous-auth在哪里配置

kubernetes-dashboard.yaml

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. labels:
  5. k8s-app: kubernetes-dashboard
  6. addonmanager.kubernetes.io/mode: Reconcile
  7. name: kubernetes-dashboard
  8. namespace: kube-system
  9. ---
  10. apiVersion: apps/v1beta2
  11. kind: Deployment
  12. metadata:
  13. name: kubernetes-dashboard
  14. namespace: kube-system
  15. labels:
  16. k8s-app: kubernetes-dashboard
  17. kubernetes.io/cluster-service: "true"
  18. addonmanager.kubernetes.io/mode: Reconcile
  19. spec:
  20. selector:
  21. matchLabels:
  22. k8s-app: kubernetes-dashboard
  23. template:
  24. metadata:
  25. labels:
  26. k8s-app: kubernetes-dashboard
  27. annotations:
  28. scheduler.alpha.kubernetes.io/critical-pod: ''
  29. spec:
  30. serviceAccountName: kubernetes-dashboard
  31. containers:
  32. - name: kubernetes-dashboard
  33. image: 10.0.11.222:5000/bigdata/kubernetes-dashboard-amd64:v1.8.0
  34. resources:
  35. limits:
  36. cpu: 100m
  37. memory: 300Mi
  38. requests:
  39. cpu: 100m
  40. memory: 100Mi
  41. ports:
  42. - containerPort: 8443
  43. protocol: TCP
  44. args:
  45. - --auto-generate-certificates
  46. volumeMounts:
  47. - name: kubernetes-dashboard-certs
  48. mountPath: /certs
  49. - name: tmp-volume
  50. mountPath: /tmp
  51. livenessProbe:
  52. httpGet:
  53. scheme: HTTPS
  54. path: /
  55. port: 8443
  56. initialDelaySeconds: 30
  57. timeoutSeconds: 30
  58. volumes:
  59. - name: kubernetes-dashboard-certs
  60. secret:
  61. secretName: kubernetes-dashboard-certs
  62. - name: tmp-volume
  63. emptyDir: {}
  64. serviceAccountName: kubernetes-dashboard
  65. tolerations:
  66. - key: "CriticalAddonsOnly"
  67. operator: "Exists"
  68. ---
  69. apiVersion: v1
  70. kind: Service
  71. metadata:
  72. name: kubernetes-dashboard
  73. namespace: kube-system
  74. labels:
  75. k8s-app: kubernetes-dashboard
  76. kubernetes.io/cluster-service: "true"
  77. addonmanager.kubernetes.io/mode: Reconcile
  78. spec:
  79. type: NodePort
  80. selector:
  81. k8s-app: kubernetes-dashboard
  82. ports:
  83. - port: 443
  84. targetPort: 8443
  • 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
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84

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地址。

kubernetes-rbac.yaml

因为kubernetes1.8.0开启了 RBAC 所以这里需要创建一个 RBAC 认证。

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. name: kubernetes-dashboard
  5. namespace: kube-system
  6. ---
  7. kind: ClusterRoleBinding
  8. apiVersion: rbac.authorization.k8s.io/v1beta1
  9. metadata:
  10. name: kubernetes-dashboard
  11. subjects:
  12. - kind: ServiceAccount
  13. name: kubernetes-dashboard
  14. namespace: kube-system
  15. roleRef:
  16. kind: ClusterRole
  17. name: cluster-admin
  18. apiGroup: rbac.authorization.k8s.io
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

dashboard安装启动

kubernetes-dashboard-certs创建

新建一个空目录:certs,然后执行下面命令:

kubectl create secret generic kubernetes-dashboard-certs --from-file=certs -n kube-system
  • 1

将上面两个文件kubernetes-dashboard.yamlkubernetes-rbac.yaml放置到同一个目录,该目录只要这两个文件,然后执行下面的命令:

安装启动

  1. # 读取当前目录配置文件进行安装启动
  2. kubectl apply -f .
  • 1
  • 2

查看pod

查看namespacekube-system下的pod

  1. kubectl get pods --namespace="kube-system"
  2. NAME READY STATUS RESTARTS AGE
  3. kubernetes-dashboard-77bd6c79b-sc5wb 1/1 Running 1 56m
  • 1
  • 2
  • 3
  • 4
  • 5

查看指定pod详情

pods/后面跟指定pod name

kubectl describe pods/kubernetes-dashboard-77bd6c79b-sc5wb --namespace="kube-system" 
  • 1

由于详情过多,此处截图只展示部分信息:

这里写图片描述

查看dashboard界面

访问以下链接(1.8.0访问 https://masterip:6443/ui 无法访问):

https://MasterIP:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
  • 1

MasterIPkubernetes集群master节点ip

kubernetes-dashboard界面:

这里写图片描述

出现的问题

首次安装,如果没有做apiserver参数配置,则可能会出现一些问题。下面就看下常见问题的解决方法

system:anonymous问题

访问dashboard网页时,可能出现下面这种报错:

  1. {
  2. "kind": "Status",
  3. "apiVersion": "v1",
  4. "metadata": {
  5. },
  6. "status": "Failure",
  7. "message": "services \"https:kubernetes-dashboard:\" is forbidden: User \"system:anonymous\" cannot get services/proxy in the namespace \"kube-system\"",
  8. "reason": "Forbidden",
  9. "details": {
  10. "name": "https:kubernetes-dashboard:",
  11. "kind": "services"
  12. },
  13. "code": 403
  14. }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

Kubernetes API Server新增了–anonymous-auth选项,允许匿名请求访问secure port。没有被其他authentication方法拒绝的请求即Anonymous requests, 这样的匿名请求的usernamesystem:anonymous, 归属的组为system:unauthenticated。并且该选线是默认的。这样一来,当采用chrome浏览器访问dashboard UI时很可能无法弹出用户名、密码输入对话框,导致后续authorization失败。为了保证用户名、密码输入对话框的弹出,需要将–anonymous-auth设置为false

解决方法:

api-server配置文件中添加--anonymous-auth=false

  1. vi /etc/systemd/system/kube-apiserver.service
  2. [Unit]
  3. Description=Kubernetes API Server
  4. Documentation=https://github.com/GoogleCloudPlatform/kubernetes
  5. After=network.target
  6. [Service]
  7. User=root
  8. ExecStart=/usr/local/bin/kube-apiserver \
  9. --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota,NodeRestriction \
  10. --advertise-address=10.0.11.222 \
  11. --allow-privileged=true \
  12. --apiserver-count=3 \
  13. --audit-policy-file=/etc/kubernetes/audit-policy.yaml \
  14. --audit-log-maxage=30 \
  15. --audit-log-maxbackup=3 \
  16. --audit-log-maxsize=100 \
  17. --audit-log-path=/var/log/kubernetes/audit.log \
  18. --authorization-mode=Node,RBAC \
  19. --anonymous-auth=false \ # 不接受匿名访问,若为true,则表示接受,此处设置为false,便于dashboard访问
  20. --bind-address=0.0.0.0 \
  21. --secure-port=6443 \
  22. --client-ca-file=/etc/kubernetes/ssl/ca.pem \
  23. --enable-swagger-ui=true \
  24. --etcd-cafile=/etc/kubernetes/ssl/ca.pem \
  25. --etcd-certfile=/etc/kubernetes/ssl/etcd.pem \
  26. --etcd-keyfile=/etc/kubernetes/ssl/etcd-key.pem \
  27. --etcd-servers=https://10.0.11.222:2379 \
  28. --event-ttl=1h \
  29. --kubelet-https=true \
  30. --insecure-bind-address=127.0.0.1 \
  31. --insecure-port=8080 \
  32. --service-account-key-file=/etc/kubernetes/ssl/ca-key.pem \
  33. --service-cluster-ip-range=10.254.0.0/16 \
  34. --service-node-port-range=30000-32000 \
  35. --tls-cert-file=/etc/kubernetes/ssl/kubernetes.pem \
  36. --tls-private-key-file=/etc/kubernetes/ssl/kubernetes-key.pem \
  37. --enable-bootstrap-token-auth \
  38. --token-auth-file=/etc/kubernetes/token.csv \
  39. --v=2
  40. Restart=on-failure
  41. RestartSec=5
  42. Type=notify
  43. LimitNOFILE=65536
  44. [Install]
  45. WantedBy=multi-user.target
  • 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

Unauthorized问题

解决了上面那个问题之后,再度访问dashboard页面,发现还是有问题,出现下面这个问题:

  1. {
  2. "kind": "Status",
  3. "apiVersion": "v1",
  4. "metadata": {
  5. },
  6. "status": "Failure",
  7. "message": "Unauthorized",
  8. "reason": "Unauthorized",
  9. "code": 401
  10. }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

解决方法: 
新建/etc/kubernetes/basic_auth_file文件,并在其中添加:

admin,admin,1002
  • 1

文件内容格式:password,username,uid

然后在api-server配置文件(即上面的配置文件)中添加--basic-auth-file=/etc/kubernetes/basic_auth_file \

保存重启kube-apiserver

  1. systemctl daemon-reload
  2. systemctl enable kube-apiserver
  3. systemctl start kube-apiserver
  4. systemctl status kube-apiserver
  • 1
  • 2
  • 3
  • 4

最后在kubernetes上执行下面这条命令:

kubectl create clusterrolebinding login-dashboard-admin --clusterrole=cluster-admin --user=admin
  • 1

将访问账号名adminkubernetes-rbac.yaml文件中指定的cluster-admin关联,获得访问权限。

getsockopt: connection timed out’问题

如果安装的docker版本为1.13及以上,并且网络畅通,flanneletcd都正常,但还是会出现getsockopt: connection timed out'的错误,则可能是iptables配置问题。具体问题:

Error: 'dial tcp 10.233.50.3:8443: getsockopt: connection timed out
  • 1

docker1.13版本开始,可能将iptables FORWARD chain的默认策略设置为DROP,从而导致ping其他Node上Pod IP失败,遇到这种问题时,需要手动设置策略为ACCEPT

sudo iptables -P FORWARD ACCEPT
  • 1

使用iptables -nL命令查看,发现Forward的策略还是drop,可是我们明明执行了iptables -P FORWARD ACCEPT。原来,docker是在这句话执行之后启动的,需要每次在docker之后再执行这句话。。。这么做有点太麻烦了,所以我们修改下docker的启动脚本:

  1. vi /usr/lib/systemd/system/docker.service
  2. [Service]
  3. Type=notify
  4. # the default is not to use systemd for cgroups because the delegate issues still
  5. # exists and systemd currently does not support the cgroup feature set required
  6. # for containers run by docker
  7. ExecStart=/usr/bin/dockerd $DOCKER_NETWORK_OPTIONS $DOCKER_OPTS $DOCKER_DNS_OPTIONS
  8. # 添加这行操作,在每次重启docker之前都会设置iptables策略为ACCEPT
  9. ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
  10. ExecReload=/bin/kill -s HUP $MAINPID
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

在启动文件中的 [Service] 下添加一行配置,即上面代码中的配置即可。

然后重启docker,再次查看dashboard网页。

参考文章: 
1. 解决Kubernetes 1.6.4 Dashboard无法访问的问题 
2. Kubernetes集群Dashboard插件安装 
3. 解决Centos7下Kubernetes(k8s)部署好之后无法访问dashboard

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/214236
推荐阅读
相关标签
  

闽ICP备14008679号