CentOS 7.9基于kubeadm部署kubernetes v1.24.13

小柒博客 Kubernetes评论447字数 18951阅读63分10秒阅读模式

一、Kubernetes简介

Kubernetes(简称K8S)是开源的容器集群管理系统,可以实现容器集群的自动化部署、自动扩缩容、维护等功能。它既是一款容器编排工具,也是全新的基于容器技术的分布式架构领先方案。在Docker技术的基础上,为容器化的应用提供部署运行、资源调度、服务发现和动态伸缩等功能,提高了大规模容器集群管理的便捷性。

K8S集群中有管理节点与工作节点两种类型。管理节点主要负责K8S集群管理,集群中各节点间的信息交互、任务调度,还负责容器、Pod、NameSpaces、PV等生命周期的管理。工作节点主要为容器和Pod提供计算资源,Pod及容器全部运行在工作节点上,工作节点通过kubelet服务与管理节点通信以管理容器的生命周期,并与集群其他节点进行通信。

二、K8s集群部署环境准备

1环境架构

IP

主机名

操作系统

Kubelet版本

用途

192.168.11.199

k8s-master

CentOS 7.9.2009

V1.24.13

管理节点

192.168.11.198

k8s-node2

CentOS 7.9.2009

V1.24.13

工作节点

192.168.11.197

k8s-node1

CentOS 7.9.2009

V1.24.13

工作节点

注:以下操作所有节点需要执行

2配置主机名

# Master

[root@localhost ~]# hostnamectl set-hostname k8s-master --static

# Node1

[root@localhost ~]# hostnamectl set-hostname k8s-node1 --static

# Node2

[root@localhost ~]# hostnamectl set-hostname k8s-node2 --static

[root@localhost ~]# su -

[root@k8s-master ~]# cat >>/etc/hosts <<EOF

192.168.11.199 k8s-master

192.168.11.198 k8s-node2

192.168.11.197 k8s-node1

EOF

3关闭防火墙和selinux

[root@k8s-master ~]# systemctl stop firewalld.service

[root@k8s-master ~]# systemctl disable firewalld.service

[root@k8s-master ~]# setenforce 0

[root@k8s-master ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

4关闭swap分区

[root@k8s-master ~]# swapoff -a

[root@k8s-master ~]# sed -i '/swap/s/^/#/g' /etc/fstab

5配置内核参数和优化

[root@k8s-master ~]# cat > /etc/sysctl.d/k8s.conf <<EOF

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

net.ipv4.ip_forward = 1

EOF

[root@k8s-master ~]# sysctl --system

6安装ipset、ipvsadm

[root@k8s-master ~]# yum -y install ipvsadm ipset

[root@k8s-master ~]# cat >/etc/modules-load.d/ipvs.conf <<EOF

# Load IPVS at boot

ip_vs

ip_vs_rr

ip_vs_wrr

ip_vs_sh

nf_conntrack

nf_conntrack_ipv4

EOF

[root@k8s-master ~]# systemctl enable --now systemd-modules-load.service

# 确认内核模块加载成功

[root@k8s-master ~]# lsmod |egrep "ip_vs|nf_conntrack_ipv4"

nf_conntrack_ipv4      15053 0

nf_defrag_ipv4            12729 1 nf_conntrack_ipv4

ip_vs_sh                     12688 0

ip_vs_wrr                    12697 0

ip_vs_rr                      12600 0

ip_vs                         145458 6 ip_vs_rr,ip_vs_sh,ip_vs_wrr

nf_conntrack            139264 2 ip_vs,nf_conntrack_ipv4

libcrc32c                    12644 3 xfs,ip_vs,nf_conntrack

7安装containerd

1)安装依赖软件包

[root@k8s-master ~]# yum -y install yum-utils device-mapper-persistent-data lvm2

2)添加阿里Docker源

[root@k8s-master ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3)添加overlay和netfilter模块

[root@k8s-master ~]# cat >>/etc/modules-load.d/containerd.conf <<EOF

overlay

br_netfilter

EOF

[root@k8s-master ~]# modprobe overlay

[root@k8s-master ~]# modprobe br_netfilter

4)安装Containerd,这里安装最新版本

[root@k8s-master ~]# yum -y install containerd.io

5)创建Containerd的配置文件

[root@k8s-master ~]# mkdir -p /etc/containerd

[root@k8s-master ~]# containerd config default > /etc/containerd/config.toml

[root@k8s-master ~]# sed -i '/SystemdCgroup/s/false/true/g' /etc/containerd/config.toml

[root@k8s-master ~]# sed -i '/sandbox_image/s/registry.k8s.io/registry.aliyuncs.com\/google_containers/g' /etc/containerd/config.toml

6)启动containerd

[root@k8s-master ~]# systemctl enable containerd

[root@k8s-master ~]# systemctl start containerd

三、安装kubectl、kubelet、kubeadm

1添加阿里kubernetes源

[root@k8s-master ~]# cat >/etc/yum.repos.d/kubernetes.repo <<EOF

[kubernetes]

name=Kubernetes

baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/

enabled=1

gpgcheck=0

repo_gpgcheck=0

gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

EOF

2安装kubectl、kubelet、kubeadm

1)查看所有的可用版本

[root@k8s-master ~]# yum list kubelet --showduplicates |grep 1.24

kubelet.x86_64      1.24.0-0      kubernetes

kubelet.x86_64      1.24.1-0      kubernetes

kubelet.x86_64      1.24.2-0      kubernetes

kubelet.x86_64      1.24.3-0      kubernetes

kubelet.x86_64      1.24.4-0      kubernetes

kubelet.x86_64      1.24.5-0      kubernetes

kubelet.x86_64      1.24.6-0      kubernetes

kubelet.x86_64      1.24.7-0      kubernetes

kubelet.x86_64      1.24.8-0      kubernetes

kubelet.x86_64      1.24.9-0      kubernetes

kubelet.x86_64      1.24.10-0    kubernetes

kubelet.x86_64      1.24.11-0    kubernetes

kubelet.x86_64      1.24.12-0    kubernetes

kubelet.x86_64      1.24.13-0    kubernetes

2)这里安装当前最新版本1.24.13

[root@k8s-master ~]# yum -y install kubectl-1.24.13 kubelet-1.24.13 kubeadm-1.24.13

3)启动kubelet

[root@k8s-master ~]# systemctl enable kubelet

[root@k8s-master ~]# systemctl start kubelet

四、部署Kubernetes Master

1初始化Kubernetes集群

1)查看k8s v1.24.13初始化所需要的镜像

[root@k8s-master ~]# kubeadm config images list --kubernetes-version=v1.24.13

registry.k8s.io/kube-apiserver:v1.24.13

registry.k8s.io/kube-controller-manager:v1.24.13

registry.k8s.io/kube-scheduler:v1.24.13

registry.k8s.io/kube-proxy:v1.24.13

registry.k8s.io/pause:3.7

registry.k8s.io/etcd:3.5.6-0

registry.k8s.io/coredns/coredns:v1.8.6

2)初始化

[root@k8s-master ~]# kubeadm init --kubernetes-version=1.24.13 \

--apiserver-advertise-address=192.168.11.199 \

--image-repository registry.aliyuncs.com/google_containers \

--pod-network-cidr=172.16.0.0/16

注:pod的网段为: 172.16.0.0/16,api server地址为Master本机IP,网段可以自定义,不冲突即可。

这一步很关键,由于kubeadm 默认从官网k8s.grc.io下载所需镜像,国内无法访问,因此需要通过--image-repository指定阿里云镜像仓库地址。

集群初始化成功后返回如下信息:

[init] Using Kubernetes version: v1.24.13

[preflight] Running pre-flight checks

[preflight] Pulling images required for setting up a Kubernetes cluster

[preflight] This might take a minute or two, depending on the speed of your internet connection

[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'

[certs] Using certificateDir folder "/etc/kubernetes/pki"

[certs] Generating "ca" certificate and key

[certs] Generating "apiserver" certificate and key

[certs] apiserver serving cert is signed for DNS names [k8s-master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.11.199]

[certs] Generating "apiserver-kubelet-client" certificate and key

[certs] Generating "front-proxy-ca" certificate and key

[certs] Generating "front-proxy-client" certificate and key

[certs] Generating "etcd/ca" certificate and key

[certs] Generating "etcd/server" certificate and key

[certs] etcd/server serving cert is signed for DNS names [k8s-master localhost] and IPs [192.168.11.199 127.0.0.1 ::1]

[certs] Generating "etcd/peer" certificate and key

[certs] etcd/peer serving cert is signed for DNS names [k8s-master localhost] and IPs [192.168.11.199 127.0.0.1 ::1]

[certs] Generating "etcd/healthcheck-client" certificate and key

[certs] Generating "apiserver-etcd-client" certificate and key

[certs] Generating "sa" key and public key

[kubeconfig] Using kubeconfig folder "/etc/kubernetes"

[kubeconfig] Writing "admin.conf" kubeconfig file

[kubeconfig] Writing "kubelet.conf" kubeconfig file

[kubeconfig] Writing "controller-manager.conf" kubeconfig file

[kubeconfig] Writing "scheduler.conf" kubeconfig file

[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"

[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"

[kubelet-start] Starting the kubelet

[control-plane] Using manifest folder "/etc/kubernetes/manifests"

[control-plane] Creating static Pod manifest for "kube-apiserver"

[control-plane] Creating static Pod manifest for "kube-controller-manager"

[control-plane] Creating static Pod manifest for "kube-scheduler"

[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"

[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s

[apiclient] All control plane components are healthy after 8.002556 seconds

[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace

[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster

[upload-certs] Skipping phase. Please see --upload-certs

[mark-control-plane] Marking the node k8s-master as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]

[mark-control-plane] Marking the node k8s-master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule node-role.kubernetes.io/control-plane:NoSchedule]

[bootstrap-token] Using token: 63la0m.5w6uqoiul22x3y7b

[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles

[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes

[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials

[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token

[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster

[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace

[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key

[addons] Applied essential addon: CoreDNS

[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane has initialized successfully!

 

To start using your cluster, you need to run the following as a regular user:

 

    mkdir -p $HOME/.kube

    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

    sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

    export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.

Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

 

kubeadm join 192.168.11.199:6443 --token 63la0m.5w6uqoiul22x3y7b \

    --discovery-token-ca-cert-hash sha256:7e9d28051f532ba950946a8fb9c602010660991c97aa46bc919bd7e01f7deac4

注:记录生成的最后部分内容,此内容需要在其它节点加入Kubernetes集群时执行。

2根据提示创建kubectl

[root@k8s-master ~]# mkdir -p $HOME/.kube

[root@k8s-master ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

[root@k8s-master ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config

[root@k8s-master ~]# export KUBECONFIG=/etc/kubernetes/admin.conf

3查看node节点和pod

[root@k8s-master ~]# kubectl get node

NAME              STATUS      ROLES               AGE    VERSION

k8s-master       NotReady    control-plane      49s     v1.24.13

[root@k8s-master ~]# kubectl get pod -A

NAMESPACE NAME                                  READY    STATUS   RESTARTS   AGE

kube-system coredns-74586cf9b6-4msgr   0/1 Pending 0 38s

kube-system coredns-74586cf9b6-r9djp    0/1 Pending 0 38s

kube-system etcd-k8s-master                    1/1 Running 0 52s

kube-system kube-apiserver-k8s-master   1/1 Running 0 52s

kube-system kube-controller-manager-k8s-master 1/1 Running 0 52s

kube-system kube-proxy-qfnzr                 1/1 Running 0 38s

kube-system kube-scheduler-k8s-master 1/1 Running 0 55s

注:node节点为NotReady,因为corednspod没有启动,缺少网络pod

4安装Pod网络插件calico(CNI)

[root@k8s-master ~]# kubectl apply -f https://docs.tigera.io/archive/v3.24/manifests/calico.yaml

poddisruptionbudget.policy/calico-kube-controllers created

serviceaccount/calico-kube-controllers created

serviceaccount/calico-node created

configmap/calico-config created

customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/caliconodestatuses.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/globalnetworksets.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/hostendpoints.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipamblocks.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipamconfigs.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipamhandles.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/ipreservations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/kubecontrollersconfigurations.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.org created

customresourcedefinition.apiextensions.k8s.io/networksets.crd.projectcalico.org created

clusterrole.rbac.authorization.k8s.io/calico-kube-controllers created

clusterrole.rbac.authorization.k8s.io/calico-node created

clusterrolebinding.rbac.authorization.k8s.io/calico-kube-controllers created

clusterrolebinding.rbac.authorization.k8s.io/calico-node created

daemonset.apps/calico-node created

deployment.apps/calico-kube-controllers created

5再次查看pod和node

[root@k8s-master ~]# kubectl get pod -A

NAMESPACE NAME                                                        READY  STATUS  RESTARTS  AGE

kube-system calico-kube-controllers-84c476996d-p5wvc 1/1       Running 0                  85s

kube-system calico-node-7lv7s                                         1/1       Running 0                  85s

kube-system coredns-74586cf9b6-4msgr                         1/1       Running 0                  2m28s

kube-system coredns-74586cf9b6-r9djp                           1/1       Running 0                 2m28s

kube-system etcd-k8s-master                                            1/1       Running 0                 2m42s

kube-system kube-apiserver-k8s-master                           1/1       Running 0                  2m42s

kube-system kube-controller-manager-k8s-master           1/1        Running 0                 2m42s

kube-system kube-proxy-qfnzr                                          1/1        Running 0                 2m28s

kube-system kube-scheduler-k8s-master                          1/1        Running 0                 2m45s

[root@k8s-master ~]# kubectl get node

NAME          STATUS     ROLES             AGE     VERSION

k8s-master   Ready        control-plane    3m7s    v1.24.13

6从节点加入Kubernetes集群

[root@k8s-node1 ~]# kubeadm join 192.168.11.199:6443 --token 63la0m.5w6uqoiul22x3y7b \

    --discovery-token-ca-cert-hash sha256:7e9d28051f532ba950946a8fb9c602010660991c97aa46bc919bd7e01f7deac4

[root@k8s-node2 ~]# kubeadm join 192.168.11.199:6443 --token 63la0m.5w6uqoiul22x3y7b \

    --discovery-token-ca-cert-hash sha256:7e9d28051f532ba950946a8fb9c602010660991c97aa46bc919bd7e01f7deac4

7再次查看Node

[root@k8s-master ~]# kubectl get nodes

NAME             STATUS      ROLES             AGE      VERSION

k8s-master      Ready         control-plane    5m47s   v1.24.13

k8s-node1       Ready          <none>            2m4s     v1.24.13

k8s-node2        Ready         <none>            2m6s     v1.24.13

8kubectl命令补全功能

[root@k8s-master ~]# yum -y install bash-completion

[root@k8s-master ~]# echo "source <(kubectl completion bash)" >> /etc/profile

[root@k8s-master ~]# source /etc/profile

五、安装kubernetes-dashboard

注:官方部署dashboard的服务没使用nodeport,将yaml文件下载到本地,在service里添加nodeport。

1下载配置文件

[root@k8s-master ~]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.1/aio/deploy/recommended.yaml

2修改配置文件

[root@k8s-master ~]# vim recommended.yaml

# 需要修改的内容如下所示

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  type: NodePort       # 增加内容
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30000  # 增加内容
  selector:
    k8s-app: kubernetes-dashboard

[root@k8s-master ~]# kubectl apply -f recommended.yaml

namespace/kubernetes-dashboard created

serviceaccount/kubernetes-dashboard created

service/kubernetes-dashboard created

secret/kubernetes-dashboard-certs created

secret/kubernetes-dashboard-csrf created

secret/kubernetes-dashboard-key-holder created

configmap/kubernetes-dashboard-settings created

role.rbac.authorization.k8s.io/kubernetes-dashboard created

clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created

rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created

clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created

deployment.apps/kubernetes-dashboard created

service/dashboard-metrics-scraper created

deployment.apps/dashboard-metrics-scraper created

3查看pod和service

[root@k8s-master ~]# kubectl get pod -n kubernetes-dashboard

NAME                                                              READY    STATUS   RESTARTS    AGE

dashboard-metrics-scraper-8c47d4b5d-984f7 1/1          Running   0                   59s

kubernetes-dashboard-6c75475678-xjqpj       1/1          Running   0                   59s

[root@k8s-master ~]# kubectl get svc -n kubernetes-dashboard

NAME                                 TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)            AGE

dashboard-metrics-scraper ClusterIP 10.101.103.150 <none>              8000/TCP         64s

kubernetes-dashboard        NodePort 10.102.71.101   <none>             443:30000/TCP 65s

4访问Dashboard页面

# 浏览器输入https://192.168.11.199:30000/,如下图所示

CentOS 7.9基于kubeadm部署kubernetes v1.24.13

5创建用户

[root@k8s-master ~]# vim dashboard-admin.yaml

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

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin
  namespace: kubernetes-dashboard  

---
apiVersion: v1
kind: Secret
metadata:
  name: kubernetes-dashboard-admin
  namespace: kubernetes-dashboard
  annotations:
    kubernetes.io/service-account.name: "admin"
type: kubernetes.io/service-account-token

[root@k8s-master ~]# kubectl apply -f dashboard-admin.yaml

serviceaccount/admin created

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

secret/kubernetes-dashboard-admin created

6创建Token

[root@k8s-master ~]# kubectl -n kubernetes-dashboard create token admin

eyJhbGciOiJSUzI1NiIsImtpZCI6IjdqTkpDS0xOeDZ6QU9XS05zQTVEV1NtQXh0V3lLdVZxX2FFODNSejFnRTQifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNjgyMDUwNjI3LCJpYXQiOjE2ODIwNDcwMjcsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbiIsInVpZCI6IjM4Nzc1ZGNmLTA1ZDYtNDllMy05MmExLTkyMmU2NTJjYTA0YSJ9fSwibmJmIjoxNjgyMDQ3MDI3LCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4ifQ.mwD3Rlntw7ODrMMtNEE05r_CSs7B-P1AbsYXBL0eTIwUdhPdP14lZNCigoz6fOBZABOQfn1MeRHS0xiEzq5EvGdMyuRBc2-nhB-fm_OzKpbUg0R2MTk3m3Q7_-q_89KY-d0qRddYsjFt4c2j4Ou4c8MRw8POi3XrLDJJNSEIJssbP2XU_QFd5uXZR1fJOuvGXwLoaZeVLG76_MW3L-lqjEJQtavJ3UpVfIR89M3o9we_fxwFb0WPGsa893QJbrJW8iBMgl_51icE-u6wNQIakPoAWOoEHqsbNYkIiE22iZtrCgi7Ba5sZreyaPZZ8qT18N4Ujq--ii2hy3H5r9B2Fg

7获取Token

[root@k8s-master ~]# Token=$(kubectl -n kubernetes-dashboard get secret |awk '/kubernetes-dashboard-admin/ {print $1}')

[root@k8s-master ~]# kubectl describe secrets -n kubernetes-dashboard ${Token} |grep token |awk 'NR==NF {print $2}'

eyJhbGciOiJSUzI1NiIsImtpZCI6IjdqTkpDS0xOeDZ6QU9XS05zQTVEV1NtQXh0V3lLdVZxX2FFODNSejFnRTQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjM4Nzc1ZGNmLTA1ZDYtNDllMy05MmExLTkyMmU2NTJjYTA0YSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDphZG1pbiJ9.XUgndocZu5fbXHbrgXCJj_tZhxCGsXBLIOF_G56RBtJiAfWmrN-znNmGnalV3G0jkfLM3DbgHsAGUn3zs_lZkKDNEaFujPigFL322QRdoEzR07yC6RVJdJ7HJ-n8z7RMc6yLRVqX0O9-qFQ0-gdAx9Srvtsj2n8Auv594oVwbohUeKMGPfA1A22elb94x2CN8THEooWbXszdvgu8PNGgi9qQydyO9xUgp-ISMfabj6dWu4IG-ypYzAYhyware7vhk3nnKuj4icDUEAkLZjsu0_duDEaFY0h2yv2SWaS4P4zXCs4wUK0MFl-EYDOZrnuVWSrCGQHC7Wfn4Sxg0AYX1Q

8使用Token登录Dashboard


注:登录后如果没有namespace可选,并且提示找不到资源,那么就是权限不足问题导致,可通过以下命令授权

[root@k8s-master ~]# kubectl create clusterrolebinding serviceaccount-cluster-admin --clusterrole=cluster-admin --user=system:serviceaccount:kubernetes-dashboard:kubernetes-dashboard

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
历史上的今天
4月
21
Wechat
微信扫一扫,加我!
weinxin
微信公众号
微信扫一扫,关注我!
weinxin
小柒博客
  • 本文由 小柒博客 发表于 2023年4月21日11:24:09
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/9052.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证