145.k8s新版本部署

发表于 linux 分类,标签:
1.设置hostname
hostnamectl set-hostname  m1
hostnamectl set-hostname  n1
hostnamectl set-hostname  n2

vi /etc/hosts
m1 192.168.2.50
n1 192.168.2.51
n2 192.168.2.51

2.禁用防火墙
systemctl stop firewalld.service 
systemctl disable firewalld.service

3.关闭交换分区
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab

4.关闭selinux
getenforce
cat /etc/selinux/config
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
cat /etc/selinux/config

5.设置仓库
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
#是否检查gpg签名文件
gpgcheck=0
#是否检查gpg签名文件
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

6.修改sysctl参数
#设置所需的sysctl参数,参数在重新启动后保持不变
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
vm.swappiness = 0
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF
#应用sysctl参数而不重新启动
sysctl --system

7.安装containerd1.6.28
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo 
yum install -y yum-utils device-mapper-persistent-data lvm2
yum install -y containerd.io containerd
如提示:No package containerd.io available.
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y containerd.io containerd
安装指定版本1.6.28
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.6.28-3.05.el7.x86_64.rpm
sudo yum install -y containerd.io-1.6.28-3.05.el7.x86_64.rpm
sudo systemctl enable --now containerd
sudo containerd --version
阿里containerd包地址
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/

systemctl stop containerd.service

containerd config default > /etc/containerd/config.toml
sed -i "s#registry.k8s.io/pause#registry.cn-hangzhou.aliyuncs.com/google_containers/pause#g" /etc/containerd/config.toml

#更改/etc/containerd/config.toml,disabled_plugins中删除cri
vi /etc/containerd/config.toml
sed -i "s#SystemdCgroup = false#SystemdCgroup = true#g" /etc/containerd/config.toml

systemctl enable --now containerd.service
systemctl status containerd.service
modprobe br_netfilter

8.安装kubelet
sudo yum install -y kubelet-1.27.3-0 kubeadm-1.27.3-0 kubectl-1.27.3-0 --disableexcludes=kubernetes --nogpgcheck
sudo systemctl daemon-reload
sudo systemctl restart kubelet
sudo systemctl enable kubelet

9.初始化
kubeadm init --image-repository=registry.aliyuncs.com/google_containers 

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

#让master参与服务调度,不做control-plane
kubectl taint node m1 node-role.kubernetes.io/control-plane-
kubectl label node m1 kubernetes.io/role=master
crictl config runtime-endpoint unix:///var/run/containerd/containerd.sock

10.加入集群
kubeadm join 172.16.64.9:6443 --token token.fake  --discovery-token-ca-cert-hash sha256:fake

11.修改网卡信息
wget --no-check-certificate https://projectcalico.docs.tigera.io/archive/v3.25/manifests/calico.yaml
#修改calico.yaml文件
vim calico.yaml
#在- name: CLUSTER_TYPE下方添加如下内容
- name: CLUSTER_TYPE
  value: "k8s,bgp"
  # 下方为新增内容
- name: IP_AUTODETECTION_METHOD
  value: "interface=网卡名称"
#例如:- name: IP_AUTODETECTION_METHOD
#例如:value: "interface=eth0" 可使用通配符,例如:interface="eth.*|en.*"

kubectl apply -f calico.yaml

12.输出nodes
kubectl cluster-info
kubectl get nodes
kubectl get pods -A -o wide

13.查看镜像
ctr image list
or
crictl images
 
#拉取镜像,分为非k8s容器用和k8s容器用,一定要加上--all-platforms
ctr i pull --all-platforms registry.xxxxx/pause:3.2
ctr -n k8s.io i pull --all-platforms registry.aliyuncs.com/google_containers/pause:3.2
或者,要登录的harbor
ctr i pull --user user:passwd --all-platforms registry.aliyuncs.com/google_containers /pause:3.2
或者,不推荐,没有--all-platforms
crictl pull --creds user:passwd registry.aliyuncs.com/google_containers /pause:3.2

#镜像打tag
镜像标记tag
ctr -n k8s.io i tag registry.xxxxx/pause:3.2 k8s.gcr.io/pause:3.2
或者,强制覆盖
ctr -n k8s.io i tag --force registry.xxxxx/pause:3.2 k8s.gcr.io/pause:3.2

#删除镜像tag
ctr -n k8s.io i rm registry.xxxxx/pause:3.2

#推送镜像
ctr i push --all-platforms  --user user:passwd registry.xxxxx/pause:3.2

#导出保存镜像
ctr -n=k8s.io  i export kube-apiserver:v1.28.0.tar xxxxx.com/kube-apiserver:v1.28.0 --all-platforms
ctr -n=k8s.io  i import kube-apiserver:v1.28.0.tar



0 篇评论

发表我的评论