Kubernetes Installation

机器配置

主机名 角色 IP 系统
centos-istio-0001 Slave 159.138.51.216 CentOS 8.2 64bit
centos-istio-0002 Slave 159.138.57.247 CentOS 8.2 64bit
centos-istio-0003 Master 182.160.9.140 CentOS 8.2 64bit

注⚠️:三台机器均已安装Docker。

允许 iptables 检查桥接流量

1
2
3
4
5
6
7
8
9
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

安装 kubeadm、kubelet 和 kubectl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable --now kubelet

查看kubelet、kubeadm和kubectl是否安装成功

使用kubeadm安装master集群

1
kubeadm init --apiserver-advertise-address=192.168.0.96 --pod-network-cidr=10.244.0.0/16

要使非 root 用户可以运行 kubectl,请运行以下命令, 它们也是 kubeadm init 输出的一部分:

1
2
3
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

或者,如果你是 root 用户,则可以运行:

1
export KUBECONFIG=/etc/kubernetes/admin.conf

安装flannel网络

1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

将Slave节点加入集群

1
2
kubeadm join 192.168.0.96:6443 --token 8axber.2vzp1am4kcr7qpxd \
--discovery-token-ca-cert-hash sha256:10e0a25cc62687435f0211feeea1896d1ea512f3233a258ab0ef56a921224436

查看集群节点状态