学习时使用版本V1.23
安装docker,参考docker学习笔记
修改docker的cgroup driver为systemd
vim /etc/docker/daemon.json
添加
{
...
"exec-opts": ["native.cgroupdriver=systemd"],
...
}
启动docker服务
systemctl enable --now docker
下载CNI plugin
mkdir -p /opt/cni/bin
wget https://github.com/containernetworking/plugins/releases/download/v0.8.2/cni-plugins-linux-amd64-v0.8.2.tgz
tar -zxvf cni-plugins-linux-amd64-v0.8.2.tgz -C /opt/cni/bin/
安装cri-dockerd
git clone https://github.com/Mirantis/cri-dockerd.git
cd cri-dockerd
mkdir bin
go build -o bin/cri-dockerd
mkdir -p /usr/local/bin
install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
cp -a packaging/systemd/* /etc/systemd/system
sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
systemctl daemon-reload
systemctl enable cri-docker.service
systemctl enable --now cri-docker.socket
下载cri-tools
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.22.0/crictl-v1.22.0-linux-amd64.tar.gz
tar -zxvf crictl-v1.22.0-linux-amd64.tar.gz -C /usr/local/bin/
安装kubeadm,kubelet,kubectl
cd /usr/local/bin
wget https://storage.googleapis.com/kubernetes-release/release/v1.23.3/bin/linux/amd64/kubeadm
wget https://storage.googleapis.com/kubernetes-release/release/v1.23.3/bin/linux/amd64/kubelet
wget https://storage.googleapis.com/kubernetes-release/release/v1.23.3/bin/linux/amd64/kubectl
sudo chmod +x {kubeadm,kubelet,kubectl}
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.4.0/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service
mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/v0.4.0/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:/usr/local/bin:g" | tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
主节点配置cgroup驱动
# kubeadm-config.yaml
kind: ClusterConfiguration
apiVersion: kubeadm.k8s.io/v1beta3
kubernetesVersion: v1.23.0
---
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
cgroupDriver: systemd
yum install -y conntrack
yum install -y socat
yum install -y iproute-tc
kubeadm init --config kubeadm-config.yaml
使用kubeadm创建集群
kuberadmin命令
kubeadm init
该命令用来初始化Kubernetes控制平面节点。
vim kubeadm-config.yaml
kubeadm-config.yaml内容
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
kind: ClusterConfiguration
apiVersion: kubeadm.k8s.io/v1beta3
kubernetesVersion: v1.23.0
---
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
cgroupDriver: systemd
kubeadm init --config kubeadm-config.yaml --ignore-preflight-errors=all
主节点启用并启动kubelet
systemctl enable --now kubelet
配置工作节点
#⽣成⽤于添加节点的kubeadm-config.yaml⽂件
kubeadm config print join-defaults > kubeadm-config.yaml
# 记住执行结果后2行 ,很重要,配置工作节点要用
修改三个地⽅:
apiServerEndpoint:连接apiserver的地址,即master的api地址,这⾥可以改为192.168.0.1:6443,如果master集群部署的话,这⾥需要改为集群vip地址
token及tlsBootstrapToken:连接master使⽤的token,这⾥需要与master上的InitConfiguration中的token配置⼀致
name:node节点的名称,如果使⽤主机名,需要确保master节点可以解析该主机名。否则的话可直接使⽤ip地址
#添加节点:
kubeadm join --config kubeadm-config.yaml
配置容器网络
学习使用的是weave Net插件
wget https://objects.githubusercontent.com/github-production-release-asset-2e65be/23059575/60bd3cab-a564-4244-9c15-3381cbddb19b?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20221111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221111T100516Z&X-Amz-Expires=300&X-Amz-Signature=b81cb4d98e9e68c4e4606a951981060a62987ccde5f371169f8aa2f9c0cf12e7&X-Amz-SignedHeaders=host&actor_id=32411982&key_id=0&repo_id=23059575&response-content-disposition=attachment%3B%20filename%3Dweave-daemonset-k8s.yaml&response-content-type=application%2Foctet-stream
wget https://objects.githubusercontent.com/github-production-release-asset-2e65be/23059575/0f3c0900-5f05-11eb-86aa-7365974ccbe6?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20221111%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20221111T095519Z&X-Amz-Expires=300&X-Amz-Signature=3383092493bd0c955e39f81ab42724c3dec46253d0befefc73a61905a288c8fc&X-Amz-SignedHeaders=host&actor_id=32411982&key_id=0&repo_id=23059575&response-content-disposition=attachment%3B%20filename%3Dweave&response-content-type=application%2Foctet-stream
kubectl apply -f weave-daemonset-k8s.yaml
安装ingress controller
- 下载yaml文件
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.5.1/deploy/static/provider/baremetal/deploy.yaml
- 修改deploy.yaml配置
修改镜像地址:
image: registry.k8s.io/ingress-nginx/controller:v1.5.1@sha256:4ba73c697770664c1e00e9f968de14e08f606ff961c76e5d7033a4a9c593c629
修改为: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.5.1@sha256:4ba73c697770664c1e00e9f968de14e08f606ff961c76e5d7033a4a9c593c629
image:registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20220916-gd32f8c343@sha256:39c5b2e3310dc4264d638ad28d9d1d96c4cbb2b2dcfb52368fe4e3c63f61e10f
修改为:image: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v20220916-gd32f8c343@sha256:39c5b2e3310dc4264d638ad28d9d1d96c4cbb2b2dcfb52368fe4e3c63f61e10f
修改Deployment的ports配置信息:添加hostPort: 80 和 443
在k8s中的master节点执行
kubectl apply -f deploy.yaml
4.查看安装结果
kubectl get all -n ingress-nginx