日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux上部署K8S集群

發(fā)布時間:2023/12/8 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux上部署K8S集群 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

部署K8S集群

  • 服務(wù)器硬件要求:三臺虛擬機服務(wù)器,操作系統(tǒng)都為centos;

    ? 硬盤最低配置:內(nèi)存2GB,CPU2核,硬盤30GB。

  • 準(zhǔn)備環(huán)境
  • master 192.168.200.110
    node1 192.168.200.120
    node2 192.168.200.130

  • 系統(tǒng)初始化

    • 關(guān)閉防火墻,禁止開機自啟
    [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disable firewalld
    • 關(guān)閉selinux
    [root@localhost ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config [root@localhost ~]# cat /etc/selinux/config
    • 關(guān)閉swap分區(qū)
    [root@localhost ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab [root@localhost ~]# reboot
    • 設(shè)置主機名
    [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 ~]#
    • 在每個節(jié)點添加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的鏈;(三臺服務(wù)配置一樣)有一些ipv4的流量不能走iptables鏈【linux內(nèi)核的一個過濾器,每個流量都會經(jīng)過他,然后再匹配是否可進入當(dāng)前應(yīng)用進程去處理】,導(dǎo)致流量丟失
    [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 ...
    • 每個節(jié)點添加時間同步
    [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.com3 May 23:19:51 ntpdate[2296]: adjust time server 20.189.79.72 offset -0.004672 sec[root@node2 ~]# ntpdate time.windows.com3 May 23:19:54 ntpdate[10912]: adjust time server 20.189.79.72 offset -0.004834 sec
    • 在每個節(jié)點安裝ipset和ipvsadm:(ipset是iptables的擴展,允許你創(chuàng)建匹配整個地址sets(地址集合)的規(guī)則。而不像普通的iptables鏈?zhǔn)蔷€性的存儲和過濾,ipvsadm命令功能:用于 設(shè)置,維護,檢查Linux內(nèi)核中的虛擬服務(wù)表)

      [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 ## 授權(quán)、運行、檢查是否加載: [root@master ~]# chmod 755 /etc/sysconfig/modules/ipvs.modules &&bash/etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4

      三臺節(jié)點安裝docker K8s

      默認(rèn)CRI(容器運行時)為Docker,因此需要先安裝Docker!

    • 獲取阿里云鏡像
    ## 獲取鏡像 [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... 已連接。 已發(fā)出 HTTP 請求,正在等待回應(yīng)... 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 元數(shù)據(jù)緩存已建立 [root@master ~]yum -y update 更新軟件
  • 安裝docker(三臺節(jié)點)
  • [root@master ~]# yum -y install docker-ce-18.06.1.ce-3.el7 ###啟動docker并設(shè)置開機自啟 [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.

    所有節(jié)點都要配置kubeadm,kubelet,kubectl鏡像

    kubelet:運行在集群所有節(jié)點上,負(fù)責(zé)啟動POD和容器kubeadm:用于初始化集群kubectl:kubenetes命令行工具,通過kubectl可以部署和管理應(yīng)用,查看各種資源,創(chuàng)建,刪除和更新組件
  • 創(chuàng)建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/ 將文件移到y(tǒng)um的目錄 [root@node2 ~]# m
  • 安裝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 設(shè)置開機自啟 Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service
  • 初始化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/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, 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命令,先復(fù)制出來,node節(jié)點加入master會使用。[root@master01 ~]# vim /etc/docker/daemon.json 修改配置文件,三個節(jié)點都要 { "exec-opts": ["native.cgroupdriver=systemd"] }

    – apiserver-advertise-address 集群通告地址
    – image-repository 由于默認(rèn)拉取鏡像地址k8s.gcr.io國內(nèi)無法訪問,這里指定阿里云鏡像倉庫地址
    – kubernetes-version K8s版本,與上面安裝的一致
    – service-cidr 集群內(nèi)部虛擬網(wǎng)絡(luò),Pod統(tǒng)一訪問入口
    – pod-network-cidr Pod網(wǎng)絡(luò),與下面部署的CNI網(wǎng)絡(luò)組件yaml中保持一致

  • 拷貝k8s認(rèn)證文件

  • [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.查看工作節(jié)點 [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網(wǎng)絡(luò)

    [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集群中創(chuàng)建一個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 90sNAME 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>

    至此,我們已經(jīng)成功部署了一個nginx的deployment,deployment控制對應(yīng)的pod的生命周期,service則對外提供相應(yīng)的服務(wù)。

    [外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(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... 已連接。 已發(fā)出 HTTP 請求,正在等待回應(yīng)... 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... 已連接。 已發(fā)出 HTTP 請求,正在等待回應(yīng)... 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])默認(rèn)Dashboard只能集群內(nèi)部訪問,修改Service為NodePort類型,暴露到外部: [root@master ~]# vi recommended.yaml spec:ports:- port: 443targetPort: 8443nodePor:30001 可以添加nodePort指定端口,然后訪問地址,必須火狐瀏覽器用https打開:https://NodeIP:30001selector:k8s-app: kubernetes-dashboardtype: 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) 12hNAME 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 全部為運行狀態(tài) 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服務(wù)器發(fā)送了一個HTTP請求。

    創(chuàng)建service account并綁定默認(rèn)cluster-admin管理員集群角色:

    [root@master ~]# kubectl create serviceaccount dashboard-admin -n kube-system 創(chuàng)建用戶 serviceaccount/dashboard-admin created [root@master ~]# kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin 用戶授權(quán) 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-adminkubernetes.io/service-account.uid: db6fba8a-b8c4-466d-88f5-8cc081520de4Type: kubernetes.io/service-account-tokenData ==== ca.crt: 1099 bytes namespace: 11 bytes token: eyJhbGciOiJSUzI1NiIsImtpZCI6ImFZb0RUWmJvYi11SC1WZDhYX2pjaldJczFzQTdNckZiSmRFWUY5c3poRHcifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tcWRweGIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZGI2ZmJhOGEtYjhjNC00NjZkLTg4ZjUtOGNjMDgxNTIwZGU0Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.Kg88J8bsP_6aF01i8l2V1VCbXH8dAKA99AlcR0qkZy6zCgwwfN1iACp36L8sVTqO6e_r-ZLbTWfQ2ex2c1b9cCpaTd1rWJmnjtEi1YRQM4-JehhAnfKmCphbAd5yATOtn7Ew79NCIQ_v5TEgw8YzI50hDhaE62c3fPlXoorPctnSAwMHQznRp4s21I2Ewvb1tC4nVTaxFb-ajVcA5EdKziao901LbM6tIOtvMQ8barOQEyrkvv7O1yyDsCPGZ9kuy53Qrk97JG8sUuBG3nhMdkhsT9pRX98J597a_TMNPrau4q2RRhTjJc2q0Zibbj6F_Py_9Z87SdNXi6V4ke8loQ使用輸出的token登錄Dashboard。

    總結(jié)

    以上是生活随笔為你收集整理的linux上部署K8S集群的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。