1 搭建K8s环境平台规划 1.1 单master集群
2 服务器硬件配置要求
3 搭建k8s集群部署方式
目前生产部署k8s集群主要有两种方式:
1️⃣kubeadm:
2️⃣二级制包:
kubeadm降低部署门槛,但是屏蔽了很多细节,遇到问题很难排查。如果想要更容易可控,推荐使用二级制包部署k8s集群,虽然手动部署麻烦点,期间可以学习很多工作原理,也有利于后期维护。
4 kubeadm搭建k8s集群
kubeadm init
kubeadm join <master节点的IP和端口>
角色 | IP |
---|---|
k8s-master | 192.168.217.100 |
k8s-node1 | 192.168.217.101 |
k8s-node2 | 192.168.217.102 |
systemctl stop firewalld
systemctl disable firewalld
# 永久
sed -i 's/enforcing/disabled/' /etc/selinux/config
# 重启
reboot
# 临时
setenforce 0
# 永久
sed -ri 's/.*swap.*/#&/' /etc/fstab
# 重启
reboot
swapoff -a
hostnamectl set-hostname <hostname>
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
cat >> /etc/hosts << EOF
192.168.217.100 k8s-master
192.168.217.101 k8s-node1
192.168.217.102 k8s-node2
EOF
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
vm.swappiness = 0
EOF
# 加载br_netfilter模块
modprobe br_netfilter
# 查看是否加载
lsmod | grep br_netfilter
# 生效
sysctl --system
yum install ntpdate -y
ntpdate time.windows.com
yum -y install ipset ipvsadm
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
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
lsmod | grep -e ipvs -e nf_conntrack_ipv4
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-18.06.3.ce-3.el7
systemctl enable docker && systemctl start docker
docker version
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
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
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
vim /etc/sysconfig/kubelet
# 修改
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"
systemctl enable kubelet
# 由于默认拉取镜像地址k8s.gcr.io国内无法访问,这里需要指定阿里云镜像仓库地址
kubeadm init \
--apiserver-advertise-address=192.168.217.100 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.18.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# 向k8s集群中添加Node节点
kubeadm join 192.168.217.100:6443 --token 4016im.eg4e10yamcbxjm59 \
--discovery-token-ca-cert-hash sha256:ce2111ce594e5189255144a72268250e5eedda87470cc3a1f69f8c973927699e
kubeadm token create --print-join-command
# 生成一个永不过期的token
kubeadm token create --ttl 0
kubectl get nodes
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get pods -n kube-system
kubectl get nodes
kubectl get cs
kubectl cluster-info
5 二进制包搭建k8s集群
角色 | IP | 组件 |
---|---|---|
k8s-master | 192.168.217.100 | kube-api-server、kube-controller-manager、kube-scheduler、docker、etcd |
k8s-node1 | 192.168.217.101 | kubelet、kube-proxy、docker、etcd |
k8s-node2 | 192.168.217.102 | kubelet、kube-proxy、docker、etcd |
4.3系统初始化
一样。节点名称 | IP |
---|---|
etcd-1 | 192.168.217.100 |
etcd-2 | 192.168.217.101 |
etcd-3 | 192.168.217.102 |
注意:为了节省机器,这里和k8s节点机器复用。也可以独立于k8s集群之外部署,只要API Server能连接即可。
wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
wget https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
chmod +x cfssl_linux-amd64 cfssljson_linux-amd64 cfssl-certinfo_linux-amd64
mv cfssl_linux-amd64 /usr/local/bin/cfssl
mv cfssljson_linux-amd64 /usr/local/bin/cfssljson
mv cfssl-certinfo_linux-amd64 /usr/bin/cfssl-certinfo
1️⃣自签证书颁发机构(CA):
mkdir -pv ~/TLS/{etcd,k8s}
cd TLS/etcd
cat > ca-config.json <<EOF
{
"signing": {
"default": {
"expiry": "87600h"
},
"profiles": {
"kubernetes": {
"expiry": "87600h",
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
]
}
}
}
}
EOF
cat > ca-csr.json <<EOF
{
"CN": "kubernetes",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "Beijing",
"ST": "Beijing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
ls -l *pem
2️⃣使用自签CA签发etcd的https证书:
cat > server-csr.json <<EOF
{
"CN": "etcd",
"hosts": [
"192.168.217.100",
"192.168.217.101",
"192.168.217.102"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "Beijing",
"L": "Beijing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes server-csr.json | cfssljson -bare server
ls -l server*pem
wget https://github.com/etcd-io/etcd/releases/download/v3.4.9/etcd-v3.4.9-linux-amd64.tar.gz
mkdir -pv /opt/etcd/{bin,cfg,ssl}
tar -zxvf etcd-v3.4.9-linux-amd64.tar.gz
mv etcd-v3.4.9-linux-amd64/{etcd,etcdctl} /opt/etcd/bin/
cat > /opt/etcd/cfg/etcd.conf << EOF
#[Member]
ETCD_NAME="etcd-1"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.217.100:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.217.100:2379"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.217.100:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.217.100:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.217.100:2380,etcd-2=https://192.168.217.101:2380,etcd-3=https://192.168.217.102:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
EOF
- ETCD_NAME:节点名称。
- ETCD_DATA_DIR:数据目录。
- ETCD_LISTEN_PEER_URLS:集群通信监听地址。
- ETCD_LISTEN_CLIENT_URLS:客户端访问监听地址 。
- ETCD_INITIAL_ADVERTISE_PEER_URLS:集群通告地址。
- ETCD_ADVERTISE_CLIENT_URLS:客户端通告地址。
- ETCD_INITIAL_CLUSTER:集群节点地址。
- ETCD_INITIAL_CLUSTER_TOKEN:集群 Token。
- ETCD_INITIAL_CLUSTER_STATE:加入集群的当前状态, new 是新集群, existing 表示加入已有集群。
cat > /usr/lib/systemd/system/etcd.service << EOF
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.targcaet
[Service]
Type=notify
EnvironmentFile=/opt/etcd/cfg/etcd.conf
ExecStart=/opt/etcd/bin/etcd \
--cert-file=/opt/etcd/ssl/server.pem \
--key-file=/opt/etcd/ssl/server-key.pem \
--peer-cert-file=/opt/etcd/ssl/server.pem \
--peer-key-file=/opt/etcd/ssl/server-key.pem \
--trusted-ca-file=/opt/etcd/ssl/ca.pem \
--peer-trusted-ca-file=/opt/etcd/ssl/ca.pem \
--logger=zap
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
cp ~/TLS/etcd/ca*pem ~/TLS/etcd/server*pem /opt/etcd/ssl/
scp -r /opt/etcd/ root@192.168.217.101:/opt/
scp /usr/lib/systemd/system/etcd.service root@192.168.217.101:/usr/lib/systemd/system/
scp -r /opt/etcd/ root@192.168.217.102:/opt/
scp /usr/lib/systemd/system/etcd.service root@192.168.217.102:/usr/lib/systemd/system/
vim /opt/etcd/cfg/etcd.conf
#[Member]
ETCD_NAME="etcd-2"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.217.101:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.217.101:2379"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.217.101:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.217.101:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.217.100:2380,etcd-2=https://192.168.217.101:2380,etcd-3=https://192.168.217.102:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
#[Member]
ETCD_NAME="etcd-3"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://192.168.217.102:2380"
ETCD_LISTEN_CLIENT_URLS="https://192.168.217.102:2379"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.217.102:2380"
ETCD_ADVERTISE_CLIENT_URLS="https://192.168.217.102:2379"
ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.217.100:2380,etcd-2=https://192.168.217.101:2380,etcd-3=https://192.168.217.102:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
systemctl daemon-reload
systemctl start etcd
systemctl enable etcd
systemctl status etcd.service
1️⃣自签证书颁发机构(CA):
cd ~/TLS/k8s/
cat > ca-config.json <<EOF
{
"signing": {
"default": {
"expiry": "87600h"
},
"profiles": {
"kubernetes": {
"expiry": "87600h",
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
]
}
}
}
}
EOF
cat > ca-csr.json <<EOF
{
"CN": "kubernetes",
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "Beijing",
"ST": "Beijing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
ll *pem
2️⃣使用自签CA签发etcd的https证书:
cat > kube-proxy-csr.json << EOF
{
"CN": "system:kube-proxy",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "BeiJing",
"ST": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cat > server-csr.json<< EOF
{
"CN": "kubernetes",
"hosts": [
"10.0.0.1",
"127.0.0.1",
"kubernetes",
"kubernetes.default",
"kubernetes.default.svc",
"kubernetes.default.svc.cluster",
"kubernetes.default.svc.cluster.local",
"192.168.217.100",
"192.168.217.101",
"192.168.217.102",
"192.168.217.1",
"192.168.217.2",
"192.168.31.198"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"L": "BeiJing",
"ST": "BeiJing",
"O": "k8s",
"OU": "System"
}
]
}
EOF
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes server-csr.json | cfssljson -bare server
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy
mkdir -pv /opt/kubernetes/{bin,cfg,ssl,logs}
wget "https://dl.k8s.io/v1.18.10/kubernetes-server-linux-amd64.tar.gz"
tar -zxvf kubernetes-server-linux-amd64.tar.gz
cd kubernetes/server/bin
cp kube-apiserver kube-scheduler kube-controller-manager /opt/kubernetes/bin
cp kubectl /usr/bin/
cat > /opt/kubernetes/cfg/kube-apiserver.conf << EOF
KUBE_APISERVER_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--etcd-servers=https://192.168.217.100:2379,https://192.168.217.101:2379,https://192.168.217.102:2379 \\
--bind-address=192.168.217.100 \\
--secure-port=6443 \\
--advertise-address=192.168.217.100 \\
--allow-privileged=true \\
--service-cluster-ip-range=10.0.0.0/24 \\
--enable-admission-plugins=NamespaceLifecycle,LimitRanger,ServiceAccount,ResourceQuota,NodeRestriction \\
--authorization-mode=RBAC,Node \\
--enable-bootstrap-token-auth=true \\
--token-auth-file=/opt/kubernetes/cfg/token.csv \\
--service-node-port-range=30000-32767 \\
--kubelet-client-certificate=/opt/kubernetes/ssl/server.pem \\
--kubelet-client-key=/opt/kubernetes/ssl/server-key.pem \\
--tls-cert-file=/opt/kubernetes/ssl/server.pem \\
--tls-private-key-file=/opt/kubernetes/ssl/server-key.pem \\
--client-ca-file=/opt/kubernetes/ssl/ca.pem \\
--service-account-key-file=/opt/kubernetes/ssl/ca-key.pem \\
--etcd-cafile=/opt/etcd/ssl/ca.pem \\
--etcd-certfile=/opt/etcd/ssl/server.pem \\
--etcd-keyfile=/opt/etcd/ssl/server-key.pem \\
--audit-log-maxage=30 \\
--audit-log-maxbackup=3 \\
--audit-log-maxsize=100 \\
--audit-log-path=/opt/kubernetes/logs/k8s-audit.log"
EOF
--logtostderr:启用日志。
--v:日志等级。
--log-dir:日志目录。
--etcd-servers:etcd集群地址。
--bind-address:监听地址。
--secure-port:https安全端口。
--advertise-address:集群通告地址。
--allow-privileged:启用授权。
--service-cluster-ip-range:Service虚拟IP地址段。
--enable-admission-plugins:准入控制模块。
--authorization-mode:认证授权,启用RBAC授权和节点自管理。
--enable-bootstrap-token-auth:启用TLS bootstrap机制。
--token-auth-file:bootstrap token文件。
--service-node-port-range:Sevice nodeport类型默认分配端口范围。
--kubelet-client-xxx:apiserver访问kubelet客户端整数。
--tls-xxx-file:apiserver https证书。
--etcd-xxxfile:连接etcd集群证书。
--audit-log-xxx:审计日志。
cp ~/TLS/k8s/ca*pem ~/TLS/k8s/server*pem ~/TLS/k8s/kube-proxy*pem /opt/kubernetes/ssl/
head -c 16 /dev/urandom | od -An -t x | tr -d ' '
cat > /opt/kubernetes/cfg/token.csv << EOF
6cd622a46af13091337d98f0ac9da4d0,kubelet-bootstrap,10001,"system:nodebootstrapper"
EOF
cat > /usr/lib/systemd/system/kube-apiserver.service << EOF
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/kubernetes/kubernetes
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kube-apiserver.conf
ExecStart=/opt/kubernetes/bin/kube-apiserver \$KUBE_APISERVER_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start kube-apiserver
systemctl enable kube-apiserver
cat > /opt/kubernetes/cfg/kube-controller-manager.conf << EOF
KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--leader-elect=true \\
--master=127.0.0.1:8080 \\
--bind-address=127.0.0.1 \\
--allocate-node-cidrs=true \\
--cluster-cidr=10.244.0.0/16 \\
--service-cluster-ip-range=10.0.0.0/24 \\
--cluster-signing-cert-file=/opt/kubernetes/ssl/ca.pem \\
--cluster-signing-key-file=/opt/kubernetes/ssl/ca-key.pem \\
--root-ca-file=/opt/kubernetes/ssl/ca.pem \\
--service-account-private-key-file=/opt/kubernetes/ssl/ca-key.pem \\
--experimental-cluster-signing-duration=87600h0m0s"
EOF
- --master:通过本地非安全本地端口8080连接apiserver。
- --leader-elect:当该组件启动多个的时候,自动选举。
- --cluster-signing-cert-file和--cluster-signing-key-file:自动为kubelet颁发证书的CA,和apiserver保持一致。
cat > /usr/lib/systemd/system/kube-controller-manager.service << EOF
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kube-controller-manager.conf
ExecStart=/opt/kubernetes/bin/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start kube-controller-manager
systemctl enable kube-controller-manager
cat > /opt/kubernetes/cfg/kube-scheduler.conf << EOF
KUBE_SCHEDULER_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--leader-elect=true \\\
--master=127.0.0.1:8080 \\
--bind-address=127.0.0.1"
EOF
- --master:通过本地非安全本地端口 8080 连接 apiserver。
- --leader-elect:当该组件启动多个时, 自动选举( HA) 。
cat > /usr/lib/systemd/system/kube-scheduler.service << EOF
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kube-scheduler.conf
ExecStart=/opt/kubernetes/bin/kube-scheduler \$KUBE_SCHEDULER_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start kube-scheduler
systemctl enable kube-scheduler
kubectl get cs
4.4.2安装Docker
步骤一样(每个节点都需要安装Docker)。mkdir -pv /opt/kubernetes/{bin,cfg,ssl,logs}
cd ~/TLS/k8s/kubernetes/server/bin
scp kubelet kube-proxy root@192.168.217.101:/opt/kubernetes/bin
scp kubelet kube-proxy root@192.168.217.102:/opt/kubernetes/bin
scp -r /opt/kubernetes/ssl/ root@192.168.217.101:/opt/kubernetes/ssl
scp -r /opt/kubernetes/ssl/ root@192.168.217.102:/opt/kubernetes/ssl
cat > ~/configure.sh << EOF
#! /bin/bash
# create TLS Bootstrapping Token
#----------------
#创建 kubelet bootstrapping 配置文件
export PATH=$PATH:/opt/kubernetes/bin
export KUBE_APISERVER="https://192.168.217.100:6443"
export BOOTSTRAP_TOKEN="6cd622a46af13091337d98f0ac9da4d0"
#创建绑定角色
kubectl create clusterrolebinding kubelet-bootstrap \
--clusterrole=system:node-bootstrapper \
--user=kubelet-bootstrap
# 设置 cluster 参数
kubectl config set-cluster kubernetes \
--certificate-authority=/opt/kubernetes/ssl/ca.pem \
--embed-certs=true \
--server=\${KUBE_APISERVER} \
--kubeconfig=bootstrap.kubeconfig
# 设置客户端认证参数
kubectl config set-credentials kubelet-bootstrap \
--token=\${BOOTSTRAP_TOKEN} \
--kubeconfig=bootstrap.kubeconfig
#设置上下文
kubectl config set-context default \
--cluster=kubernetes \
--user=kubelet-bootstrap \
--kubeconfig=bootstrap.kubeconfig
kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
#-------------
#创建 kube-proxy 配置文件
kubectl config set-cluster kubernetes \
--certificate-authority=/opt/kubernetes/ssl/ca.pem \
--embed-certs=true \
--server=\${KUBE_APISERVER} \
--kubeconfig=kube-proxy.kubeconfig
kubectl config set-credentials kube-proxy \
--client-certificate=/opt/kubernetes/ssl/kube-proxy.pem \
--client-key=/opt/kubernetes/ssl/kube-proxy-key.pem \
--embed-certs=true \
--kubeconfig=kube-proxy.kubeconfig
kubectl config set-context default \
--cluster=kubernetes \
--user=kube-proxy \
--kubeconfig=kube-proxy.kubeconfig
kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
EOF
scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.217.101:/opt/kubernetes/cfg
scp bootstrap.kubeconfig kube-proxy.kubeconfig root@192.168.217.102:/opt/kubernetes/cfg
cat > /opt/kubernetes/cfg/kubelet.conf << EOF
KUBELET_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--hostname-override=k8s-node1 \\
--network-plugin=cni \\
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \\
--bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \\
--cert-dir=/opt/kubernetes/ssl \\
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
EOF
cat > /opt/kubernetes/cfg/kubelet.conf << EOF
KUBELET_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--hostname-override=k8s-node2 \\
--network-plugin=cni \\
--kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig \\
--bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig \\
--cert-dir=/opt/kubernetes/ssl \\
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
EOF
- --hostname-override:显示名称,集群中唯一。
- --network-plugin:启用CNI网络插件。
- --kubeconfig:用于连接apiserver。
- --cert-dir:kubelet证书生成目录。
- --pod-infra-container-image:管理Pod网络容器的镜像。
cat > /usr/lib/systemd/system/kubelet.service << EOF
[Unit]
Description=Kubernetes Kubelet
After=docker.service
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kubelet.conf
ExecStart=/opt/kubernetes/bin/kubelet \$KUBELET_OPTS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable kubelet
systemctl start kubelet
cat > /opt/kubernetes/cfg/kube-proxy.conf << EOF
KUBE_PROXY_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig \\
--hostname-override=k8s-node1"
EOF
cat > /opt/kubernetes/cfg/kube-proxy.conf << EOF
KUBE_PROXY_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes/logs \\
--kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig \\
--hostname-override=k8s-node2"
EOF
cat > /usr/lib/systemd/system/kube-proxy.service << EOF
[Unit]
Description=Kubernetes Proxy
After=network.target
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kube-proxy.conf
ExecStart=/opt/kubernetes/bin/kube-proxy \$KUBE_PROXY_OPTS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable kube-proxy
systemctl start kube-proxy
4.7部署CNI网络插件步骤
一样。kubectl get csr
kubectl certificate approve <NAME>
(查询pod 节点的报错信息)
Kubectl delete pod glusterfs-manager-5db655f6bb-m5swg -n yunxiao
(删除某个pod节点)
(强制删除某个pod节点,通常出现在某节点卡死时)
(查看Jenkins slave在k8s集群里节点的ip)
(查询dns在k8s集群里节点的ip)
(查看package-switch 节点pv 的值)
helm install -n sat-agent-edas /thor-download/yunxiao/helm-charts/230-aegis-sat/sat-agent-edas --set nameserver=10.103.3.146
(手动在thor容器里安装模块)
注: 也可登录k8s-ui检查
k8s-ui: https://${k8s_master_ip}:8443
k8s-token: cat /root/.kube/dashboard.token
K8S 的dashboard部署后 要先在K8S的dashboard里面通过修改deployment升级thor的前后端镜像到对应版本,如下图,然后k8s会自动重启pod