Master 安装
#!/bin/bash
hostnamectl set-hostname k8s-master
sed -i 's/=enforcing/=disabled/' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
sed -i '/swap/s/^/# /' /etc/fstab
swapoff -a
free -m
ssh-keygen
yum -y install yum-utils vim
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates
yum install -y docker-ce-19.03.13 docker-ce-cli-19.03.13 containerd.io
systemctl enable docker
systemctl start docker
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
yum clean all
yum makecache
yum list kubelet --showduplicates
yum install -y kubelet-1.17.4 kubeadm-1.17.4 kubectl-1.17.4
systemctl enable kubelet
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf
cat <<EOF > kube-images.sh
#!/bin/bash
url=registry.cn-hangzhou.aliyuncs.com/google_containers
version=v1.17.17
images=(\`kubeadm config images list --kubernetes-version=\$version 2>/dev/null | awk -F '/' '{print \$2}'\`)
for imagename in \${images[@]}; do
docker pull \$url/\$imagename
docker tag \$url/\$imagename k8s.gcr.io/\$imagename
docker rmi -f \$url/\$imagename
done
EOF
source kube-images.sh
docker images
ip a | grep 24
kubeadm init --apiserver-advertise-address 192.168.122.50 --pod-network-cidr=10.20.0.0/16
echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >> ~/.bashrc
source .bashrc
kubeadm token list
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
echo '199.232.68.133 raw.githubusercontent.com' >> /etc/hosts
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl label node k8s-node1 node-role.kubernetes.io/worker=worker
kubectl label node k8s-node2 node-role.kubernetes.io/worker=worker
kubectl get nodes
Nodes 安装
#!/bin/bash
hostnamectl set-hostname k8s-node
sed -i 's/=enforcing/=disabled/' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
sed -i '/swap/s/^/# /' /etc/fstab
swapoff -a
free -m
ssh-keygen
yum -y install yum-utils vim
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates
yum install -y docker-ce-19.03.13 docker-ce-cli-19.03.13 containerd.io
systemctl enable docker
systemctl start docker
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
yum clean all
yum makecache
yum list kubelet --showduplicates
yum install -y kubelet-1.17.4 kubeadm-1.17.4 kubectl-1.17.4
systemctl enable kubelet
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf
kubeadm join 192.168.122.50:6443 --token vrfirn.ai5map8t7q1cksqf --discovery-token-ca-cert-hash sha256:bf32046b26b9f8e686b4aa2776f5027a7f0306a3243e68e92ff29b2f26cc07ca