部署K8S集群

  1. 服务器硬件要求:三台虚拟机服务器,操作系统都为centos;

    ​ 硬盘最低配置:内存2GB,CPU2核,硬盘30GB。

    1. 准备环境

    master 192.168.200.110
    node1 192.168.200.120
    node2 192.168.200.130

  2. 系统初始化

    • 关闭防火墙,禁止开机自启
    [root@localhost ~]# systemctl stop firewalld
    [root@localhost ~]# systemctl disable firewalld
    
    • 关闭selinux
    [root@localhost ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config  
    [root@localhost ~]# cat /etc/selinux/config
    
    
    • 关闭swap分区
    [root@localhost ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab
    [root@localhost ~]# reboot
    
    • 设置主机名
    [root@localhost ~]# hostnamectl set-hostname master
    [root@localhost ~]# bash
    [root@master ~]# 
    
    [root@localhost ~]# hostnamectl set-hostname node1
    [root@localhost ~]# bash
    [root@node1 ~]# 
    
    [root@localhost ~]# hostnamectl set-hostname node2
    [root@localhost ~]# bash
    [root@node2 ~]# 
    
    • 在每个节点添加hosts
    [root@master ~]# vi /etc/hosts
    192.168.200.110 master
    192.168.200.120 node1
    192.168.200.130 node2
    ~         
    验证互ping
    [root@master ~]# ping node2
    PING node2 (192.168.200.130) 56(84) bytes of data.
    64 bytes from node2 (192.168.200.130): icmp_seq=1 ttl=64 time=0.844 ms
    64 bytes from node2 (192.168.200.130): icmp_seq=2 ttl=64 time=0.461 ms
    
    
    • 将桥接的IPv4流量传递到iptables的链;(三台服务配置一样)有一些ipv4的流量不能走iptables链【linux内核的一个过滤器,每个流量都会经过他,然后再匹配是否可进入当前应用进程去处理】,导致流量丢失
    [root@master ~]# cat > /etc/sysctl.d/k8s.conf << EOF
    > 
    > net.bridge.bridge-nf-call-ip6tables = 1
    > 
    > net.bridge.bridge-nf-call-iptables = 1
    > 
    > EOF
    [root@master ~]# sysctl --system     刷新生效
    * Applying /usr/lib/sysctl.d/00-system.conf ...
    * Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
    kernel.yama.ptrace_scope = 0
    * Applying /usr/lib/sysctl.d/50-default.conf ...
    kernel.sysrq = 16
    kernel.core_uses_pid = 1
    net.ipv4.conf.default.rp_filter = 1
    net.ipv4.conf.all.rp_filter = 1
    net.ipv4.conf.default.accept_source_route = 0
    net.ipv4.conf.all.accept_source_route = 0
    net.ipv4.conf.default.promote_secondaries = 1
    net.ipv4.conf.all.promote_secondaries = 1
    fs.protected_hardlinks = 1
    fs.protected_symlinks = 1
    * Applying /etc/sysctl.d/99-sysctl.conf ...
    * Applying /etc/sysctl.d/k8s.conf ...
    * Applying /etc/sysctl.conf ...
    
    
    • 每个节点添加时间同步
    [root@node2 ~]# yum install ntpdate -y    安装时间同步
    [root@master ~]# ntpdate time.windows.com  开启时间同步
     3 May 23:19:47 ntpdate[2980]: adjust time server 20.189.79.72 offset -0.005315 sec
    
    [root@node1 ~]# ntpdate time.windows.com
     3 May 23:19:51 ntpdate[2296]: adjust time server 20.189.79.72 offset -0.004672 sec
    
    [root@node2 ~]# ntpdate time.windows.com
     3 May 23:19:54 ntpdate[10912]: adjust time server 20.189.79.72 offset -0.004834 sec
    
    • 在每个节点安装ipset和ipvsadm:(ipset是iptables的扩展,允许你创建匹配整个地址sets(地址集合)的规则。而不像普通的iptables链是线性的存储和过滤,ipvsadm命令功能:用于 设置,维护,检查Linux内核中的虚拟服务表)

      [root@node2 ~]# yum -y install ipset ipvsadm 安装ipset和ipsadm
      [root@master ~]# cat > /etc/sysconfig/modules/ipvs.modules <<EOF  配置文件
      > #!/bin/bash
      > modprobe -- ip_vs
      > modprobe -- ip_vs_rr
      > modprobe -- ip_vs_wrr
      > modprobe -- ip_vs_sh
      > modprobe -- nf_conntrack_ipv4
      > EOF
      ## 授权、运行、检查是否加载:
      [root@master ~]# chmod 755 /etc/sysconfig/modules/ipvs.modules &&bash/etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4  
      

      三台节点安装docker K8s

      默认CRI(容器运行时)为Docker,因此需要先安装Docker!

      1. 获取阿里云镜像
    ## 获取镜像
    [root@master ~]# wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O  /etc/yum.repos.d/docker-ce.repo
    --2022-05-03 23:22:49--  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 119.96.65.198, 119.96.65.202, 119.96.64.238, ...
    正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|119.96.65.198|:80... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度:2081 (2.0K) [application/octet-stream]
    正在保存至: “/etc/yum.repos.d/docker-ce.repo”
    
    100%[==================================================================================================================================================>] 2,081       --.-K/s 用时 0s      
    
    2022-05-03 23:22:50 (275 MB/s) - 已保存 “/etc/yum.repos.d/docker-ce.repo” [2081/2081])
    ##刷新yum源
    [root@master ~]# yum clean all  
    已加载插件:fastestmirror
    正在清理软件源: base docker-ce-stable extras updates
    Cleaning up everything
    Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
    Cleaning up list of fastest mirrors
    [root@master ~]# yum makecache
    已加载插件:fastestmirror
    Determining fastest mirrors
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
    updates                                                                                                                                                              | 2.9 kB  00:00:00     
    (1/14): base/7/x86_64/group_gz                                                                                                                                       | 153 kB  00:00:00     
    (2/14): base/7/x86_64/filelists_db                                                                                                                                   | 7.2 MB  00:00:01     
    (3/14): docker-ce-stable/7/x86_64/updateinfo                                                                                                                         |   55 B  00:00:00     
    (4/14): base/7/x86_64/other_db                                                                                                                                       | 2.6 MB  00:00:00     
    (5/14): docker-ce-stable/7/x86_64/filelists_db                                                                                                                       |  31 kB  00:00:00     
    (6/14): docker-ce-stable/7/x86_64/primary_db                                                                                                                         |  75 kB  00:00:00     
    (7/14): docker-ce-stable/7/x86_64/other_db                                                                                                                           | 123 kB  00:00:00     
    (8/14): extras/7/x86_64/primary_db                                                                                                                                   | 246 kB  00:00:00     
    (9/14): extras/7/x86_64/other_db                                                                                                                                     | 147 kB  00:00:00     
    (10/14): extras/7/x86_64/filelists_db                                                                                                                                | 277 kB  00:00:00     
    (11/14): base/7/x86_64/primary_db                                                                                                                                    | 6.1 MB  00:00:02     
    (12/14): updates/7/x86_64/other_db                                                                                                                                   | 1.0 MB  00:00:00     
    (13/14): updates/7/x86_64/filelists_db                                                                                                                               | 8.2 MB  00:00:04     
    (14/14): updates/7/x86_64/primary_db                                                                                                                                 |  15 MB  00:00:06     
    元数据缓存已建立
    [root@master ~]yum -y update  更新软件
    
    1. 安装docker(三台节点)
    [root@master ~]# yum -y install docker-ce-18.06.1.ce-3.el7
    ###启动docker并设置开机自启
    [root@master ~]# systemctl enable docker && systemctl start docker
    Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
    
    

    所有节点都要配置kubeadm,kubelet,kubectl镜像

    kubelet:运行在集群所有节点上,负责启动POD和容器
    
    kubeadm:用于初始化集群
    
    kubectl:kubenetes命令行工具,通过kubectl可以部署和管理应用,查看各种资源,创建,删除和更新组件
    
    1. 创建yum源的文件
    [root@node2 ~]# cat > kubernetes.repo << EOF
    > [kubernetes]
    > name=Kubernetes
    > baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
    > enabled=1
    > gpgcheck=1
    > repo_gpgcheck=1
    > gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    > EOF
    [root@node2 ~]# mv kubernetes.repo /etc/yum.repos.d/  将文件移到yum的目录
    [root@node2 ~]# m
    
    
    1. 安装kubeadm,kubelet,kubectl
    [root@node1 etc]# yum install -y kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0
    [root@node1 etc]# systemctl enable kubelet  设置开机自启
    Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service
    
    
    1. 初始化kubeadm(只在master机器上)
    [root@master yum.repos.d]# kubeadm init \
    >   --apiserver-advertise-address=192.168.200.120 \
    >   --image-repository registry.aliyuncs.com/google_containers \
    >   --kubernetes-version v1.23.0 \
    >   --service-cidr=10.96.0.0/12 \
    >   --pod-network-cidr=10.244.0.0/16 \
    >   --ignore-preflight-errors=all
    [init] Using Kubernetes version: v1.23.0
    [preflight] Running pre-flight checks
    	[WARNING Swap]: swap is enabled; production deployments should disable swap unless testing the NodeSwap feature gate of the kubelet
    [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'
    
    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.200.110:6443 --token rhbbob.v6njal97il1vlx74 \
    	--discovery-token-ca-cert-hash sha256:47a6fe2b1e400310acf2a020798f22d00b43dc46d3d8e5d0eddd8865cdc5f3e9 
    [root@master kubelet.service.d]# 
     初始化之后,会输出一个join命令,先复制出来,node节点加入master会使用。
     [root@master01 ~]# vim /etc/docker/daemon.json   修改配置文件,三个节点都要
    {
    "exec-opts": ["native.cgroupdriver=systemd"]
    }
    
    
    
    

    – apiserver-advertise-address 集群通告地址
    – image-repository 由于默认拉取镜像地址k8s.gcr.io国内无法访问,这里指定阿里云镜像仓库地址
    – kubernetes-version K8s版本,与上面安装的一致
    – service-cidr 集群内部虚拟网络,Pod统一访问入口
    – pod-network-cidr Pod网络,与下面部署的CNI网络组件yaml中保持一致

  3. 拷贝k8s认证文件

[root@master kubelet.service.d]# mkdir -p $HOME/.kube
[root@master kubelet.service.d]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master kubelet.service.d]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
[root@master kubelet.service.d]# 
[root@master ~]# scp /etc/kubernetes/admin.conf root@node1:/root/
The authenticity of host 'node1 (192.168.200.120)' can't be established.
ECDSA key fingerprint is SHA256:ESmmyN7sUeSWqsTVabY6UOjt322FOm+q9O7lohc25VU.
ECDSA key fingerprint is MD5:78:4c:85:76:6e:29:02:5b:5c:44:bf:c3:6f:66:11:e4.

查看工作节点
[root@master kubelet.service.d]# kubectl get nodes
NAME     STATUS     ROLES                  AGE     VERSION
master   NotReady   control-plane,master   4m15s   v1.23.0

[root@node1 bridge]# kubeadm join 192.168.200.110:6443 --token rhbbob.v6njal97il1vlx74 --discovery-token-ca-cert-hash sha256:47a6fe2b1e400310acf2a020798f22d00b43dc46d3d8e5d0eddd8865cdc5f3e9 
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.


[root@node2 yum.repos.d]# kubeadm join 192.168.200.110:6443 --token rhbbob.v6njal97il1vlx74 --discovery-token-ca-cert-hash sha256:47a6fe2b1e400310acf2a020798f22d00b43dc46d3d8e5d0eddd8865cdc5f3e9 
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

[root@master kubelet.service.d]# kubectl get nodes    拉取成功
NAME     STATUS     ROLES                  AGE   VERSION
master   NotReady   control-plane,master   50m   v1.23.0
node1    NotReady   <none>                 73s   v1.23.0
node2    NotReady   <none>                 35m   v1.23.0

安装pod网络

[root@master flannel]# wget https://docs.projectcalico.org/v3.20/manifests/calico.yaml --no-check-certificate

[root@master flannel]# kubectl apply -f calico.yaml
configmap/calico-config unchanged
customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org configured
customresourcedefinition.apiextensions.k8s.io/caliconodestatuses.crd.projectcalico.org configured
##验证集群及组件
[root@master flannel]# kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   11h   v1.23.0
node1    Ready    <none>                 11h   v1.23.0
node2    Ready    <none>                 11h   v1.23.0
[root@master flannel]# kubectl get pods --namespace kube-system
NAME                                      READY   STATUS    RESTARTS      AGE
calico-kube-controllers-7c845d499-n6kv4   1/1     Running   0             9m41s
calico-node-85rhs                         1/1     Running   0             9m41s
calico-node-d4n4q                         1/1     Running   0             9m41s
calico-node-zqjtn                         1/1     Running   0             9m41s
coredns-6d8c4cb4d-l78gv                   1/1     Running   0             12h
coredns-6d8c4cb4d-r6mvw                   1/1     Running   0             12h
etcd-master                               1/1     Running   0             12h
kube-apiserver-master                     1/1     Running   0             12h
kube-controller-manager-master            1/1     Running   2 (11h ago)   12h
kube-proxy-9wbvj                          1/1     Running   0             12h
kube-proxy-g72xh                          1/1     Running   2 (11h ago)   11h
kube-proxy-w54v6                          1/1     Running   0             11h
kube-scheduler-master                     1/1     Running   1 (11h ago)   12h
[root@master flannel]# kubectl get service
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   12h
[root@master flannel]#  kubectl get svc --namespace kube-system
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   12h


测试kubernetes集群

在Kubernetes集群中创建一个pod,验证是否正常运行:以nginx为例子

[root@master flannel]# kubectl create deployment nginx --image=nginx
deployment.apps/nginx created
[root@master flannel]# kubectl expose deployment nginx --port=88 --type=NodePort --target-port=80 --name=nginx-service
service/nginx-service exposed
[root@master flannel]# kubectl get pod,svc  显示正常运行
NAME                         READY   STATUS    RESTARTS   AGE
pod/nginx-85b98978db-6685d   1/1     Running   0          90s

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/kubernetes      ClusterIP   10.96.0.1        <none>        443/TCP        12h
service/nginx-service   NodePort    10.105.133.186   <none>        88:31441/TCP   9s
[root@master flannel]# curl http://192.168.200.110:31441 从任意一个主机访问
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

至此,我们已经成功部署了一个nginx的deployment,deployment控制对应的pod的生命周期,service则对外提供相应的服务。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5CsLjGo1-1665476260040)(C:\Users\十七\AppData\Roaming\Typora\typora-user-images\image-20220504134146103.png)]

部署Dashboard

[root@master ~]#  wget http://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
--2022-05-04 13:45:55--  http://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.110.133, 185.199.111.133, ...
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml [跟随至新的 URL]
--2022-05-04 13:45:55--  https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7543 (7.4K) [text/plain]
正在保存至: “recommended.yaml”

100%[==================================================================================================================================================>] 7,543       --.-K/s 用时 0s      

2022-05-04 13:45:56 (28.6 MB/s) - 已保存 “recommended.yaml” [7543/7543])

 默认Dashboard只能集群内部访问,修改Service为NodePort类型,暴露到外部:
[root@master ~]# vi recommended.yaml
spec:
  ports:
    - port: 443
      targetPort: 8443
      nodePor:30001   可以添加nodePort指定端口,然后访问地址,必须火狐浏览器用https打开:https://NodeIP:30001
  selector:
    k8s-app: kubernetes-dashboard
    type: NodePort
---
[root@master ~]# kubectl apply -f recommended.yaml   配置文件一定要注意空格那些
namespace/kubernetes-dashboard unchanged
serviceaccount/kubernetes-dashboard unchanged
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
[root@master ~]# kubectl get pods,svc -n kube-system
NAME                                          READY   STATUS    RESTARTS      AGE
pod/calico-kube-controllers-7c845d499-n6kv4   1/1     Running   0             64m
pod/calico-node-85rhs                         1/1     Running   0             64m
pod/calico-node-d4n4q                         1/1     Running   0             64m
pod/calico-node-zqjtn                         1/1     Running   0             64m
pod/coredns-6d8c4cb4d-l78gv                   1/1     Running   0             12h
pod/coredns-6d8c4cb4d-r6mvw                   1/1     Running   0             12h
pod/etcd-master                               1/1     Running   0             12h
pod/kube-apiserver-master                     1/1     Running   0             12h
pod/kube-controller-manager-master            1/1     Running   2 (12h ago)   12h
pod/kube-proxy-9wbvj                          1/1     Running   0             12h
pod/kube-proxy-g72xh                          1/1     Running   2 (12h ago)   12h
pod/kube-proxy-w54v6                          1/1     Running   0             12h
pod/kube-scheduler-master                     1/1     Running   1 (12h ago)   12h

NAME               TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
service/kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   12h
[root@master ~]# kubectl get pods -n kubernetes-dashboard    全部为运行状态
NAME                                         READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-799d786dbf-djzvj   1/1     Running   0          4m37s
kubernetes-dashboard-6b6b86c4c5-p5s2r        1/1     Running   0          4m37s
浏览器登录,IP前一定要加https,直接加i会提示客户端向HTTPS服务器发送了一个HTTP请求。

创建service account并绑定默认cluster-admin管理员集群角色:

[root@master ~]# kubectl create serviceaccount dashboard-admin -n kube-system   创建用户
serviceaccount/dashboard-admin created
[root@master ~]# kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin    用户授权
clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created
[root@master ~]# kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')   获取token
Name:         dashboard-admin-token-qdpxb
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: dashboard-admin
              kubernetes.io/service-account.uid: db6fba8a-b8c4-466d-88f5-8cc081520de4

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1099 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6ImFZb0RUWmJvYi11SC1WZDhYX2pjaldJczFzQTdNckZiSmRFWUY5c3poRHcifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tcWRweGIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZGI2ZmJhOGEtYjhjNC00NjZkLTg4ZjUtOGNjMDgxNTIwZGU0Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.Kg88J8bsP_6aF01i8l2V1VCbXH8dAKA99AlcR0qkZy6zCgwwfN1iACp36L8sVTqO6e_r-ZLbTWfQ2ex2c1b9cCpaTd1rWJmnjtEi1YRQM4-JehhAnfKmCphbAd5yATOtn7Ew79NCIQ_v5TEgw8YzI50hDhaE62c3fPlXoorPctnSAwMHQznRp4s21I2Ewvb1tC4nVTaxFb-ajVcA5EdKziao901LbM6tIOtvMQ8barOQEyrkvv7O1yyDsCPGZ9kuy53Qrk97JG8sUuBG3nhMdkhsT9pRX98J597a_TMNPrau4q2RRhTjJc2q0Zibbj6F_Py_9Z87SdNXi6V4ke8loQ

使用输出的token登录Dashboard。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐