如何通过kubeadm安装Kubernetes
创建:
2024-08-29 14:50
更新:
2024-08-29 15:06
访问:
524
主词:
k8s 安装
描述:
k8s做为一个老大哥,安装kubernetes是一个不大不小的问题,我们通过kubeadm安装k8s,又简单又方便。
0.安装containerd和配置linux系统
在/etc/sysctl.conf中追加以下内容并保存
net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1
执行以下命令使之生效 重启系统时要重新执行此命令
modprobe br_netfilter sysctl -p
安装containered
apt install containerd
配置containerd
# 导出containerd配置以修改 mkdir /etc/containerd containerd config default > /etc/containerd/config.toml
- 修改配置文件SystemdCgroup=true使用系统Cgroup
- 修改pause镜像地址为阿里地址registry.aliyuncs.com/google_containers/pause:3.9
修改containered代理地址为可用地址
(1).修改配置文件.位置/etc/containerd/config.yaml
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
(2).创建文件夹 /etc/containerd/certs.d/docker.io
(3).在新创建文件夹里创建文件hosts.toml写入以下内容,保存即可
server = "https://docker.io"
[host."https://docker.example.com"] 这里可换为ali的镜像代理
capabilities = ["pull", "resolve"]最后重启
sudo systemctl restart containerd
1.安装必要的软件及更新
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
2.下载google cloud公开签名密钥
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg
3.添加k8s仓库
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
4.添加缺少的软件key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B53DC80D13EDEF05
5.安装kubeadm等k8s组件
sudo apt-get update
sudo apt-get install -y kubectl kubelet kubeadm
6.配置kubelet为开机启动
systemctl daemon-reload
systemctl enable kubelet
7.主结点初始化
kubeadm init --apiserver-advertise-address=$(hostname -i) \
--apiserver-advertise-address=192.168.0.134 \
--apiserver-cert-extra-sans=127.0.0.1 \
--pod-network-cidr=10.244.0.0/16 \
--image-repository=registry.aliyuncs.com/google_containers --ignore-preflight-errors=Mem --fail-swap-on=false
8.设置主结点可调度
kubectl taint node k8s-master node-role.kubernetes.io/control-plane-
9.flannel网络安装
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
10.kubectl命令行工具配置设置
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config