参考文章:https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
- 安装前准备
# 创建目录
mkdir -p ~/.local/bin
# 将上一步的目录放到PATH中
vim ~/.bash_profile
PATH=$PATH:$HOME/bin:~/.local/bin
source ~/.bash_profile
# 开启ipv4转发
vim /etc/sysctl.conf
net.ipv4.ip_forward=1
- 安装工具kubelet、kubeadm、kubectl:
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=0
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 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
sudo systemctl enable --now kubelet
- 安装工具kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.12.0/kind-linux-amd64
chmod +x ./kind
mv ./kind ~/.local/bin
- 安装工具minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod a+x chmod a+x minikube
mv minikube-linux-amd64 ~/.local/bin/minikube
- 完整shell
/bin/bash
# 基础环境
mkdir -p ~/.local/bin
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
# 安装工具kubelet、kubeadm、kubectl
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=0
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
yum update
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
sudo systemctl enable --now kubelet
# 安装工具kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.12.0/kind-linux-amd64
chmod +x ./kind
mv ./kind ~/.local/bin
# 安装工具minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
chmod a+x chmod a+x minikube
mv minikube-linux-amd64 ~/.local/bin/minikube
# 修改PATH
#vim ~/.bash_profile
#PATH=$PATH:$HOME/bin:~/.local/bin
#source ~/.bash_profile