1. 部署规划
2. 安装containerd
(以下四个主机,需进行同样操作)
wget https://github.com/containerd/containerd/releases/download/v1.6.20/containerd-1.6.20-linux-amd64.tar.gz-P /usr/local/src/
tar -xvf containerd-1.6.20-linux-amd64.tar.gz
cp bin/* /usr/local/bin/
在一台测试机,安装containerd,获取containerd.service文件.
apt install containerd -y
ls /lib/systemd/system/containerd.service
将containerd.service分别拷贝到四个主机
cp containerd.service /lib/systemd/system/
mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
61 sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7"
153 [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://i81dnvmn.mirror.aliyuncs.com"]
systemctl start containerd
systemctl enable containerd
systemctl status containerd
3. 安装runc
(以下四个主机,需进行同样操作)
wget https://github.com/opencontainers/runc/releases/download/v1.1.5/runc.amd64 -P /usr/local/src/
chmod a+x runc.amd64
cp runc.amd64 /usr/bin/runc
4. 安装crictl
(以下四个主机,需进行同样操作)
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.26.1/crictl-v1.26.1-linux-amd64.tar.gz -P /usr/local/src
tar -xvf crictl-v1.26.1-linux-amd64.tar.gz
cp crictl /usr/local/bin/
cat /etc/crictl.yaml
runtime-endpoint: "unix:///run/containerd/containerd.sock"
image-endpoint: "unix:///run/containerd/containerd.sock"
timeout: 10
debug: false
5. 安装nerdctl
(以下四个主机,需进行同样操作)
wget https://github.com/containerd/nerdctl/releases/download/v1.3.0/nerdctl-full-1.3.0-linux-amd64.tar.gz -P /usr/local/src
tar -xvf nerdctl-full-1.3.0-linux-amd64.tar.gz
cp bin/* /usr/local/bin/
6. 安装kubelet、kubeadm、kubectl
(以下四个主机,需进行同样操作)
配置阿里云镜像源:
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet=1.26.3-00 kubeadm=1.26.3-00 kubectl=1.26.3-00
7. kubeadm部署k8s集群
(以上优化及下载镜像,四个主机,需进行同样操作)
优化内核参数:
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
vm.max_map_count = 262144
kernel.pid_max = 4194303
fs.file-max = 1000000
net.ipv4.tcp_max_tw_buckets = 6000
net.netfilter.nf_conntrack_max = 2097152
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
vm.swappiness=0
vim /etc/security/limits.conf
soft core unlimited
hard core unlimited
soft nproc 1000000
hard nproc 1000000
soft nofile 1000000
hard nofile 1000000
soft memlock 32000
hard memlock 32000
soft msgqueue 8192000
hard msgqueue 8192000
reboot
modprobe br_netfilter
modprobe ip_conntrack
sysctl -p
下载镜像:
kubeadm config images list --kubernetes-version v1.26.3
kubeadm config images pull --image-repository="registry.cn-hangzhou.aliyuncs.com/google_containers" --kubernetes-version=1.26.3
(在master1执行操作)
创建kubernetes集群:
kubeadm init --apiserver-advertise-address=172.31.7.101 --apiserver-bind-port=6443 --kubernetes-version=v1.24.3 --pod-network-cidr=10.100.0.0/16 --service-cidr=10.200.0.0/16 --service-dns-domain=cluster.local --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
在master2 node1 node2分别创建.kube目录,将master1上config拷贝到.kube目录.
mkdir /root/.kube/
scp /root/.kube/config root@172.31.7.102:/root/.kube/
scp /root/.kube/config root@172.31.7.111:/root/.kube/
scp /root/.kube/config root@172.31.7.112:/root/.kube/
(加入节点,需要另外三台机器,分别执行操作)
kubeadm join 172.31.7.101:6443 --token iumwc9.qgo5aml1pcssoj5c \
--discovery-token-ca-cert-hash sha256:7fa39e3da9ded155df2765b3139e1e1bd5cedb035eb5c1129a5caad94735c600
下载calico yaml文件:
<在master1执行操作>
wget https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/calico-etcd.yaml -P /usr/local/src/
vim calico-etcd.yaml
4436 value: "10.100.0.0/16"
kubectl apply -f calico-etcd.yaml
kubectl get node
kubectl get pod -A
8. 部署一个nginx容器
vim nginx.yaml
- name: http
port: 80
protocol: TCP
targetPort: 80
nodePort: 30004
kubectl create ns myserver
kubectl apply -f nginx.yaml
curl 172.31.7.101:30004
netstat -tanlp|grep 30004
浏览器访问: 172.31.7.101:30004
9. 部署一个tomcat容器
vim tomcat.yaml
- name: http
port: 80
protocol: TCP
targetPort: 8080
nodePort: 30005
kubectl apply -f tomcat.yaml
10. 部署dashboard
在node2下载镜像
nerdctl pull kubernetesui/dashboard:v2.7.0
在master1载创建dashboard
kubectl apply -f dashboard-v2.7.0.yaml
kubectl apply -f admin-user.yaml
kubectl apply -f admin-secret.yaml
kubectl get pod -A