Kubernetes实战指南(三十四): 高可用安装K8s集群1.20.x
<p>@</p><div class="toc"><div class="toc-container-header">目录</div><ul><li>1. 安装说明</li><li>2. 节点规划</li><li>3. 基本配置</li><li>4. 内核配置</li><li>5. 基本组件安装</li><li>6. 高可用组件安装</li><li>7. 集群初始化</li><li>8. 高可用Master</li><li>9. 添加Node节点</li><li>10. Calico安装</li><li>11. Metrics Server部署</li><li>12. Dashboard部署</li></ul></div><p></p><h2 id="1-安装说明">1. 安装说明</h2>
<p>虽然K8s 1.20版本宣布将在1.23版本之后将不再维护dockershim,意味着K8s将不直接支持Docker,不过大家不必过于担心。一是在1.23版本之前我们仍然可以使用Docker,二是dockershim肯定会有人接盘,我们同样可以使用Docker,三是Docker制作的镜像仍然可以在其他Runtime环境中使用,所以大家不必过于恐慌。</p>
<p>本次安装采用的是Kubeadm安装工具,安装版本是K8s 1.20+,采用的系统为CentOS 7.9,其中Master节点3台,Node节点2台,高可用工具采用HAProxy + KeepAlived,<strong>高可用架构视频讲解点我</strong></p>
<p><strong>前沿技术,快人一步,点我了解~</strong></p>
<h2 id="2-节点规划">2. 节点规划</h2>
<table>
<thead>
<tr>
<th style="text-align: center">主机名</th>
<th style="text-align: center">IP地址</th>
<th style="text-align: center">角色</th>
<th style="text-align: center">配置</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">k8s-master01 ~ 03</td>
<td style="text-align: center">192.168.0.201 ~ 203</td>
<td style="text-align: center">Master/Worker节点</td>
<td style="text-align: center">2C2G 40G</td>
</tr>
<tr>
<td style="text-align: center">k8s-node01 ~ 02</td>
<td style="text-align: center">192.168.0.204 ~ 205</td>
<td style="text-align: center">Worker节点</td>
<td style="text-align: center">2C2G 40G</td>
</tr>
<tr>
<td style="text-align: center">k8s-master-lb</td>
<td style="text-align: center">192.168.0.236</td>
<td style="text-align: center">VIP</td>
<td style="text-align: center">VIP不占用机器</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th style="text-align: center">信息</th>
<th style="text-align: center">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center">系统版本</td>
<td style="text-align: center">CentOS 7.9</td>
</tr>
<tr>
<td style="text-align: center">Docker版本</td>
<td style="text-align: center">19.03.x</td>
</tr>
<tr>
<td style="text-align: center">K8s版本</td>
<td style="text-align: center">1.20.x</td>
</tr>
<tr>
<td style="text-align: center">Pod网段</td>
<td style="text-align: center">172.168.0.0/16</td>
</tr>
<tr>
<td style="text-align: center">Service网段</td>
<td style="text-align: center">10.96.0.0/12</td>
</tr>
</tbody>
</table>
<h2 id="3-基本配置">3. 基本配置</h2>
<p>所有节点配置hosts</p>
<pre><code># cat /etc/hosts
192.168.0.201 k8s-master01
192.168.0.202 k8s-master02
192.168.0.203 k8s-master03
192.168.0.236 k8s-master-lb # 如果不是高可用集群,该IP为Master01的IP
192.168.0.204 k8s-node01
192.168.0.205 k8s-node02
</code></pre>
<p>yum源配置</p>
<pre><code>curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
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
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
</code></pre>
<p>必备工具安装</p>
<pre><code>yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git -y
</code></pre>
<p><strong>成为K8s架构师只需一步,点我了解~</strong></p>
<p>所有节点关闭防火墙、selinux、dnsmasq、swap。服务器配置如下:</p>
<pre><code>systemctl disable --now firewalld
systemctl disable --now dnsmasq
systemctl disable --now NetworkManager
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
</code></pre>
<p>关闭swap分区</p>
<pre><code>swapoff -a && sysctl -w vm.swappiness=0
sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab
</code></pre>
<p>安装ntpdate</p>
<pre><code>rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
yum install ntpdate -y
</code></pre>
<p>所有节点同步时间。时间同步配置如下:</p>
<pre><code>ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' >/etc/timezone
ntpdate time2.aliyun.com
</code></pre>
<p>加入到crontab</p>
<pre><code>*/5 * * * * ntpdate time2.aliyun.com
</code></pre>
<p>所有节点配置limit:</p>
<pre><code>ulimit -SHn 65535
vim /etc/security/limits.conf
# 末尾添加如下内容
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited
</code></pre>
<p>Master01节点免密钥登录其他节点:</p>
<pre><code>ssh-keygen -t rsa
for i in k8s-master01 k8s-master02 k8s-master03 k8s-node01 k8s-node02;do ssh-copy-id -i .ssh/id_rsa.pub $i;done
</code></pre>
<p>下载安装所有的源码文件:</p>
<pre><code>cd /root/ ; git clone https://github.com/dotbalo/k8s-ha-install.git
</code></pre>
<p>所有节点升级系统并重启:</p>
<pre><code>yum update -y&& reboot
</code></pre>
<p><strong>掌握K8s就是掌握云计算的未来,点我了解~</strong></p>
<h2 id="4-内核配置">4. 内核配置</h2>
<p>所有节点安装ipvsadm:</p>
<pre><code>yum install ipvsadm ipset sysstat conntrack libseccomp -y
</code></pre>
<p>所有节点配置ipvs模块</p>
<pre><code>vim /etc/modules-load.d/ipvs.conf
# 加入以下内容
ip_vs
ip_vs_lc
ip_vs_wlc
ip_vs_rr
ip_vs_wrr
ip_vs_lblc
ip_vs_lblcr
ip_vs_dh
ip_vs_sh
ip_vs_fo
ip_vs_nq
ip_vs_sed
ip_vs_ftp
ip_vs_sh
nf_conntrack_ipv4
ip_tables
ip_set
xt_set
ipt_set
ipt_rpfilter
ipt_REJECT
ipip
</code></pre>
<p>加载内核配置</p>
<pre><code>systemctl enable --now systemd-modules-load.service
</code></pre>
<p>开启一些k8s集群中必须的内核参数,所有节点配置k8s内核</p>
<pre><code>cat <<EOF > /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
fs.may_detach_mounts = 1
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
fs.file-max=52706963
fs.nr_open=52706963
net.netfilter.nf_conntrack_max=2310720
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl =15
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_orphans = 327680
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.ip_conntrack_max = 65536
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_timestamps = 0
net.core.somaxconn = 16384
EOF
sysctl --system
</code></pre>
<h2 id="5-基本组件安装">5. 基本组件安装</h2>
<p>所有节点安装Docker-ce 19.03</p>
<pre><code>yum install docker-ce-19.03.* -y
</code></pre>
<p>所有节点设置开机自启动Docker</p>
<pre><code>systemctl daemon-reload && systemctl enable --now docker
</code></pre>
<p>安装k8s组件</p>
<pre><code>yum list kubeadm.x86_64 --showduplicates | sort -r
</code></pre>
<p>所有节点安装最新版本kubeadm</p>
<pre><code>yum install kubeadm -y
</code></pre>
<p>默认配置的pause镜像使用gcr.io仓库,国内可能无法访问,所以这里配置Kubelet使用阿里云的pause镜像:</p>
<pre><code>cat >/etc/sysconfig/kubelet<<EOF
KUBELET_EXTRA_ARGS="--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2"
EOF
</code></pre>
<p>设置Kubelet开机自启动</p>
<pre><code>systemctl daemon-reload
systemctl enable --now kubelet
</code></pre>
<p><strong>高薪职业,永不失业,点我了解~</strong></p>
<h2 id="6-高可用组件安装">6. 高可用组件安装</h2>
<p><strong>注意:如果不是高可用集群或者在云上安装,haproxy和keepalived无需安装</strong><br>
所有Master节点通过yum安装HAProxy和KeepAlived:</p>
<pre><code>yum install keepalived haproxy -y
</code></pre>
<p>所有Master节点配置HAProxy(详细配置参考HAProxy文档,所有Master节点的HAProxy配置相同):</p>
<pre><code># mkdir /etc/haproxy
# vim /etc/haproxy/haproxy.cfg
global
maxconn2000
ulimit-n16384
log127.0.0.1 local0 err
stats timeout 30s
defaults
log global
modehttp
optionhttplog
timeout connect 5000
timeout client50000
timeout server50000
timeout http-request 15s
timeout http-keep-alive 15s
frontend monitor-in
bind *:33305
mode http
option httplog
monitor-uri /monitor
frontend k8s-master
bind 0.0.0.0:16443
bind 127.0.0.1:16443
mode tcp
option tcplog
tcp-request inspect-delay 5s
default_backend k8s-master
backend k8s-master
mode tcp
option tcplog
option tcp-check
balance roundrobin
default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
server k8s-master01 192.168.0.201:6443check
server k8s-master02 192.168.0.202:6443check
server k8s-master03 192.168.0.203:6443check
</code></pre>
<p>所有Master节点配置KeepAlived,配置不一样,注意区分<br>
注意每个节点的IP和网卡(interface参数)<br>
Master01节点的配置:</p>
<pre><code># mkdir /etc/keepalived
# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
script_user root
enable_script_security
}
vrrp_script chk_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 5
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface ens192
mcast_src_ip 192.168.0.201
virtual_router_id 51
priority 101
advert_int 2
authentication {
auth_type PASS
auth_pass K8SHA_KA_AUTH
}
virtual_ipaddress {
192.168.0.236
}
# track_script {
# chk_apiserver
# }
}
</code></pre>
<p>Master02节点的配置:</p>
<pre><code>! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
script_user root
enable_script_security
}
vrrp_script chk_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 5
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens192
mcast_src_ip 192.168.0.202
virtual_router_id 51
priority 100
advert_int 2
authentication {
auth_type PASS
auth_pass K8SHA_KA_AUTH
}
virtual_ipaddress {
192.168.0.236
}
# track_script {
# chk_apiserver
# }
}
</code></pre>
<p>Master03节点的配置:</p>
<pre><code>! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
script_user root
enable_script_security
}
vrrp_script chk_apiserver {
script "/etc/keepalived/check_apiserver.sh"
interval 5
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens192
mcast_src_ip 192.168.0.203
virtual_router_id 51
priority 100
advert_int 2
authentication {
auth_type PASS
auth_pass K8SHA_KA_AUTH
}
virtual_ipaddress {
192.168.0.236
}
# track_script {
# chk_apiserver
# }
}
</code></pre>
<p>注意上述的健康检查是关闭的,集群建立完成后再开启:</p>
<pre><code># track_script {
# chk_apiserver
# }
</code></pre>
<p>配置KeepAlived健康检查文件:</p>
<pre><code># cat /etc/keepalived/check_apiserver.sh
#!/bin/bash
err=0
for k in $(seq 1 3)
do
check_code=$(pgrep haproxy)
if [[ $check_code == "" ]]; then
err=$(expr $err + 1)
sleep 1
continue
else
err=0
break
fi
done
if [[ $err != "0" ]]; then
echo "systemctl stop keepalived"
/usr/bin/systemctl stop keepalived
exit 1
else
exit 0
fi
chmod +x /etc/keepalived/check_apiserver.sh
启动haproxy和keepalived
# systemctl daemon-reload
# systemctl enable --now haproxy
# systemctl enable --now keepalived
</code></pre>
<p>测试VIP</p>
<pre><code># ping 192.168.0.236 -c 4
PING 192.168.0.236 (192.168.0.236) 56(84) bytes of data.
64 bytes from 192.168.0.236: icmp_seq=1 ttl=64 time=0.464 ms
64 bytes from 192.168.0.236: icmp_seq=2 ttl=64 time=0.063 ms
64 bytes from 192.168.0.236: icmp_seq=3 ttl=64 time=0.062 ms
64 bytes from 192.168.0.236: icmp_seq=4 ttl=64 time=0.063 ms
</code></pre>
<p><strong>方向比努力更重要,点我了解~</strong></p>
<h2 id="7-集群初始化">7. 集群初始化</h2>
<p>Master01节点创建new.yaml配置文件如下:</p>
<pre><code>apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: 7t2weq.bjbawausm0jaxury
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.0.201
bindPort: 6443
nodeRegistration:
criSocket: /var/run/dockershim.sock
name: k8s-master01
taints:
- effect: NoSchedule
key: node-role.kubernetes.io/master
---
apiServer:
certSANs:
- 192.168.0.236
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: 192.168.0.236:16443
controllerManager: {}
dns:
type: CoreDNS
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.20.0
networking:
dnsDomain: cluster.local
podSubnet: 172.168.0.0/16
serviceSubnet: 10.96.0.0/12
scheduler: {}
</code></pre>
<p><strong>注意:如果不是高可用集群,192.168.0.236:16443改为master01的地址,16443改为apiserver的端口,默认是6443,注意更改v1.20.0为自己服务器kubeadm的版本:kubeadm version</strong><br>
将new.yaml文件复制到其他master节点,之后所有Master节点提前下载镜像,可以节省初始化时间:</p>
<pre><code>kubeadm config images pull --config /root/new.yaml
</code></pre>
<p>所有节点设置开机自启动kubelet</p>
<pre><code>systemctl enable --now kubelet(如果启动失败无需管理,初始化成功以后即可启动)
</code></pre>
<p>Master01节点初始化,初始化以后会在/etc/kubernetes目录下生成对应的证书和配置文件,之后其他Master节点加入Master01即可:</p>
<pre><code>kubeadm init --config /root/new.yaml--upload-certs
</code></pre>
<p>初始化成功以后,会产生Token值,用于其他节点加入时使用,因此要记录下初始化成功生成的token值(令牌值):</p>
<pre><code>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 .yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of the control-plane node running the following command on each as root:
kubeadm join 192.168.0.236:16443 --token 7t2weq.bjbawausm0jaxury \
--discovery-token-ca-cert-hash sha256:8c92ecb336be2b9372851a9af2c7ca1f7f60c12c68f6ffe1eb513791a1b8a908 \
--control-plane --certificate-key ac2854de93aaabdf6dc440322d4846fc230b290c818c32d6ea2e500fc930b0aa
Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.0.236:16443 --token 7t2weq.bjbawausm0jaxury \
--discovery-token-ca-cert-hash sha256:8c92ecb336be2b9372851a9af2c7ca1f7f60c12c68f6ffe1eb513791a1b8a908
</code></pre>
<p>Master01节点配置环境变量,用于访问Kubernetes集群:</p>
<pre><code>cat <<EOF >> /root/.bashrc
export KUBECONFIG=/etc/kubernetes/admin.conf
EOF
source /root/.bashrc
</code></pre>
<p>查看节点状态:</p>
<pre><code> # kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master01 NotReady control-plane,master 74s v1.20.0
</code></pre>
<p>采用初始化安装方式,所有的系统组件均以容器的方式运行并且在kube-system命名空间内,此时可以查看Pod状态:</p>
<pre><code># kubectl get pods -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE
coredns-777d78ff6f-kstsz 0/1 Pending 0 14m <none> <none>
coredns-777d78ff6f-rlfr5 0/1 Pending 0 14m <none> <none>
etcd-k8s-master01 1/1 Running 0 14m 192.168.0.201 k8s-master01
kube-apiserver-k8s-master01 1/1 Running 0 13m 192.168.0.201 k8s-master01
kube-controller-manager-k8s-master01 1/1 Running 0 13m 192.168.0.201 k8s-master01
kube-proxy-8d4qc 1/1 Running 0 14m 192.168.0.201 k8s-master01
kube-scheduler-k8s-master01 1/1 Running 0 13m 192.168.0.201 k8s-master01
</code></pre>
<h2 id="8-高可用master">8. 高可用Master</h2>
<p>初始化其他master加入集群</p>
<pre><code>kubeadm join 192.168.0.236:16443 --token 7t2weq.bjbawausm0jaxury \
--discovery-token-ca-cert-hash sha256:8c92ecb336be2b9372851a9af2c7ca1f7f60c12c68f6ffe1eb513791a1b8a908 \
--control-plane --certificate-key ac2854de93aaabdf6dc440322d4846fc230b290c818c32d6ea2e500fc930b0aa
</code></pre>
<h2 id="9-添加node节点">9. 添加Node节点</h2>
<pre><code>kubeadm join 192.168.0.236:16443 --token 7t2weq.bjbawausm0jaxury \
--discovery-token-ca-cert-hash sha256:8c92ecb336be2b9372851a9af2c7ca1f7f60c12c68f6ffe1eb513791a1b8a908
</code></pre>
<p>查看集群状态:</p>
<pre><code># kubectlget node
NAME STATUS ROLES AGE VERSION
k8s-master01 NotReady control-plane,master 8m53s v1.20.0
k8s-master02 NotReady control-plane,master 2m25s v1.20.0
k8s-master03 NotReady control-plane,master 31s v1.20.0
k8s-node01 NotReady <none> 32s v1.20.0
k8s-node02 NotReady <none> 88s v1.20.0
</code></pre>
<h2 id="10-calico安装">10. Calico安装</h2>
<p><strong>K8s架构师学习路径,点我了解~</strong></p>
<p>以下步骤只在master01执行</p>
<pre><code>cd /root/k8s-ha-install && git checkout manual-installation-v1.20.x && cd calico/
</code></pre>
<p>修改calico-etcd.yaml的以下位置</p>
<pre><code>sed -i 's#etcd_endpoints: "http://<ETCD_IP>:<ETCD_PORT>"#etcd_endpoints: "https://192.168.0.201:2379,https://192.168.0.202:2379,https://192.168.0.203:2379"#g' calico-etcd.yaml
ETCD_CA=`cat /etc/kubernetes/pki/etcd/ca.crt | base64 | tr -d '\n'`
ETCD_CERT=`cat /etc/kubernetes/pki/etcd/server.crt | base64 | tr -d '\n'`
ETCD_KEY=`cat /etc/kubernetes/pki/etcd/server.key | base64 | tr -d '\n'`
sed -i "s@# etcd-key: null@etcd-key: ${ETCD_KEY}@g; s@# etcd-cert: null@etcd-cert: ${ETCD_CERT}@g; s@# etcd-ca: null@etcd-ca: ${ETCD_CA}@g" calico-etcd.yaml
sed -i 's#etcd_ca: ""#etcd_ca: "/calico-secrets/etcd-ca"#g; s#etcd_cert: ""#etcd_cert: "/calico-secrets/etcd-cert"#g; s#etcd_key: "" #etcd_key: "/calico-secrets/etcd-key" #g' calico-etcd.yaml
POD_SUBNET=`cat /etc/kubernetes/manifests/kube-controller-manager.yaml | grep cluster-cidr= | awk -F= '{print $NF}'`
sed -i 's@# - name: CALICO_IPV4POOL_CIDR@- name: CALICO_IPV4POOL_CIDR@g; s@# value: "192.168.0.0/16"@value: '"${POD_SUBNET}"'@g' calico-etcd.yaml
</code></pre>
<p>创建calico</p>
<pre><code>kubectl apply -f calico-etcd.yaml
</code></pre>
<h2 id="11-metrics-server部署">11. Metrics Server部署</h2>
<p>在新版的Kubernetes中系统资源的采集均使用Metrics-server,可以通过Metrics采集节点和Pod的内存、磁盘、CPU和网络的使用率。<br>
将Master01节点的front-proxy-ca.crt复制到所有Node节点</p>
<pre><code>scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node01:/etc/kubernetes/pki/front-proxy-ca.crt
scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node(其他节点自行拷贝):/etc/kubernetes/pki/front-proxy-ca.crt
</code></pre>
<p>安装metrics server</p>
<pre><code>cd /root/k8s-ha-install/metrics-server-0.4.x-kubeadm/
# kubectlcreate -f comp.yaml
serviceaccount/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
service/metrics-server created
deployment.apps/metrics-server created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
</code></pre>
<p>等待kube-system命令空间下的Pod全部启动后,查看状态</p>
<pre><code># kubectltop node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
k8s-master01 109m 2% 1296Mi 33%
k8s-master02 99m 2% 1124Mi 29%
k8s-master03 104m 2% 1082Mi 28%
k8s-node01 55m 1% 761Mi 19%
k8s-node02 53m 1% 663Mi 17%
</code></pre>
<h2 id="12-dashboard部署">12. Dashboard部署</h2>
<pre><code>cd /root/k8s-ha-install/dashboard/
# kubectlcreate -f .
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
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
</code></pre>
<p>在谷歌浏览器(Chrome)启动文件中加入启动参数,用于解决无法访问Dashboard的问题,参考图:</p>
<pre><code>--test-type --ignore-certificate-errors
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/202012121300229.png"><br>
更改dashboard的svc为NodePort:</p>
<pre><code>kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
</code></pre>
<p><img src="https://img-blog.csdnimg.cn/20201212130105853.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FpbnJ1YW4xODU2,size_16,color_FFFFFF,t_70"><br>
将ClusterIP更改为NodePort(如果已经为NodePort忽略此步骤):<br>
查看端口号:<br>
<img src="https://img-blog.csdnimg.cn/20201212130124372.png"><br>
根据自己的实例端口号,通过任意安装了kube-proxy的宿主机或者VIP的IP+端口即可访问到dashboard:<br>
访问Dashboard:https://192.168.0.236:18282(请更改18282为自己的端口),选择登录方式为令牌(即token方式)<br>
<img src="https://img-blog.csdnimg.cn/20201212130140188.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FpbnJ1YW4xODU2,size_16,color_FFFFFF,t_70"><br>
查看token值:</p>
<pre><code># kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
Name: admin-user-token-r4vcp
Namespace: kube-system
Labels: <none>
Annotations:kubernetes.io/service-account.name: admin-user
kubernetes.io/service-account.uid: 2112796c-1c9e-11e9-91ab-000c298bf023
Type:kubernetes.io/service-account-token
Data
====
ca.crt: 1025 bytes
namespace:11 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXI0dmNwIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyMTEyNzk2Yy0xYzllLTExZTktOTFhYi0wMDBjMjk4YmYwMjMiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.bWYmwgRb-90ydQmyjkbjJjFt8CdO8u6zxVZh-19rdlL_T-n35nKyQIN7hCtNAt46u6gfJ5XXefC9HsGNBHtvo_Ve6oF7EXhU772aLAbXWkU1xOwQTQynixaypbRIas_kiO2MHHxXfeeL_yYZRrgtatsDBxcBRg-nUQv4TahzaGSyK42E_4YGpLa3X3Jc4t1z0SQXge7lrwlj8ysmqgO4ndlFjwPfvg0eoYqu9Qsc5Q7tazzFf9mVKMmcS1ppPutdyqNYWL62P1prw_wclP0TezW1CsypjWSVT4AuJU8YmH8nTNR1EXn8mJURLSjINv6YbZpnhBIPgUGk1JYVLcn47w
</code></pre>
<p>将token值输入到令牌后,单击登录即可访问Dashboard<br>
<img src="https://img-blog.csdnimg.cn/20201212130209567.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FpbnJ1YW4xODU2,size_16,color_FFFFFF,t_70"><br>
<strong>K8s全栈架构师培训课程,点我了解</strong></p><br><br>
来源:https://www.cnblogs.com/dukuan/p/14124600.html
頁:
[1]