k8s安装dashboard及账号密码登陆

1.k8s安装管理后台

(1)获取yaml配置文件
 wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/d
 eploy/recommended.yaml
 修改node端口暴露

k8s安装dashboard及账号密码登陆_第1张图片

# (2)docker拉取后台模板镜像
 docker pull kubernetesui/dashboard:v2.0.0-beta8

# (3)加载该配置文件
kubectl apply -f recommended.yaml

#(4)查看dashboard是否运行
kubectl get pods,svc -n kubernetes-dashboard -o wide
# (5)创建用户
apiVersion: v1
kind: ServiceAccount
metadata:
    name: liyuan
    namespace: kubernetes-dashboard
---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
    name: liyuan
roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole 
    name: liyuan
subjects:
- kind: ServiceAccount
  name: liyuan
  namespace: kubernetes-dashboard
#(6)获取用户token
kubectl get sa,secrets -n kubernetes-dashboard

#(7) 为集群创建用户并绑定管理员角色
kubectl create clusterrolebinding dashboard-cluster --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:kubernetes-dashboard

#(8)获取指定用户token
kubectl describe secrets kubernetes-dashboard-token-xxx -n kubernetes-dashboard



#(9)通过地址访问
https://x.x.x.:30001/#/node?namespace=default

//查看pod是否运行
kubectl get pod -n kubernetes-dashboard

//查看某一pod状态
kubectl describe pod nginx-****

kubectl get nodes
kubectl describe node nodeName
//其中internalIP即为NodeIP

kubectl get pods
kubectl describe pod podName

//对于现在的我来说有点复杂,因此我选择删除从节点

//主节点
kubectl drain liyuan-node1 --delete-local-data
kubectl delete nodes liyuan-node1

//查看所有pod
kubectl get pods --all-namespaces -o wide

//移除dash-board
kubectl delete -f recommended.yaml


kubectl create -f recommended.yaml

//查看其端口
kubectl get svc -n kubernetes-dashboard

//切记关闭防火墙
 systemctl stop firewalld.service
 
# 2.k8s添加账号密码登陆
#(1)修改配置文件
vim /etc/kubernetes/manifests/ kube-apiserver.yaml

在这里插入图片描述c.
(2)在相应位置书写相应如下文件
在这里插入图片描述

#(3)进行角色绑定
kubectl create clusterrolebinding login-on-dashboard-with-cluster-admin --clusterrole=cluster-admin --user=liyuan

#(4)修改相关配置
kubectl edit deploy kubernetes-dashboard -n kubernetes-dashboard

deployment.apps/kubernetes-dashboard edited

k8s安装dashboard及账号密码登陆_第2张图片

//给匿名用户添加权限

kubectl create clusterrolebinding test:anonymous --clusterrole=cluster-admin --user=system:anonymous

第二种方式


apiVersion: v1
kind: ServiceAccount
metadata:
 name: liyuan
 namespace: kubernetes-dashboard

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
 name: liyuan
roleRef:
 apiGroup: rbac.authorization.k8s.io
 kind: ClusterRole
 name: liyuan
subjects:
- kind: ServiceAccount
 name: liyuan
 namespace: kubernetes-dashboard
kubectl get secret -n kubernetes-dashboard
kubectl describe secret -n kubernetes-dashboard 上述命令查到的名为李源的用户

你可能感兴趣的:(k8s)