k8s 安装 dashboard与卸载

查看版本命令:kubectl version #输出服务端和客户端的版本信息

或者docker images | grep kube

Releases · kubernetes/dashboard · GitHub 具体去这里查看对应的版本

# cd /opt

下载文件,注意版本号

# wget –tries=40 https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml

将文件名recommended.yaml变更为kubernetes-dashboard-2.5.1.yaml

创建pod

# kubectl apply -f kubernetes-dashboard-2.5.1.yaml

查看创建成功,查看所有po

# kubectl get po --all-namespaces

查看现有的所有服务

# kubectl get svc --all-namespaces

删除现有的dashboard服务

# kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard

# kubectl delete service dashboard-metrics-scraper --namespace=kubernetes-dashboard

删除现有的dashboard pod

# kubectl delete deployment kubernetes-dashboard --namespace=kubernetes-dashboard

# kubectl delete deployment dashboard-metrics-scraper --namespace=kubernetes-dashboard

因为Service是ClusterIP类型,为了方便使用,我们可通过kubectl --namespace=kubernetes-dashboard edit service kubernetes-dashboard修改成NodePort类型,如图所示。

kubernetes-dashboard一直ContainerCreating的解决方法

k8s 安装 dashboard与卸载_第1张图片

保存修改,此时已经为Service分配了端口32200,如图所示。

kubectl --namespace=kubernetes-dashboard get service kubernetes-dashboard

kubectl delete secret kubernetes-dashboard-certs -n kube-system

Kubernetes创建Dashboard超级管理员账户

vi admin-sa.yaml

kind: ClusterRoleBinding

apiVersion: rbac.authorization.k8s.io/v1

metadata:

  name: admin

  annotations:

    rbac.authorization.kubernetes.io/autoupdate: "true"

roleRef:

  kind: ClusterRole

  name: cluster-admin

  apiGroup: rbac.authorization.k8s.io

subjects:

- kind: ServiceAccount

  name: admin

  namespace: kube-system

---

apiVersion: v1

kind: ServiceAccount

metadata:

  name: admin

  namespace: kube-system

  labels:

    kubernetes.io/cluster-service: "true"

    addonmanager.kubernetes.io/mode: Reconcile

创建admin用户

# kubectl create -f admin-sa.yaml

clusterrolebinding.rbac.authorization.k8s.io/admin created

serviceaccount/admin created

查看admin用户

# kubectl get secret -n kube-system|grep admin

admin-token-npgtv                                kubernetes.io/service-account-token   3      82s

获取admin用户token

# kubectl describe secret -n kube-system admin-token-npgtv

kubernetes-dashboard一直ContainerCreating的解决方法

kubectl get pod -A
kubectl describe pod kubernetes-dashboard-6bd77794f-zkzh5 -n kubernetes-dashboard
原因:

node1之前反复添加过,添加之前需要清除下网络

在Node上执行如下操作:

重置kubernetes服务,重置网络。删除网络配置,link

systemctl stop kubelet

systemctl stop docker

rm -rf /var/lib/cni/

rm -rf /var/lib/kubelet/*

rm -rf /etc/cni/

ifconfig cni0 down

ifconfig flannel.1 down

ifconfig docker0 down

ip link delete cni0

ip link delete flannel.1

systemctl start docker

systemctl start kubelet

kubeadm reset

重新创建集群


kubernetes-dashboard正常运行了

你可能感兴趣的:(kubernetes,docker,运维)