开始语
一位普通的程序员,慢慢在努力变强!
温馨提示:初始化k8s的前置配置,请查看以下连接!
k8s初始化前的基础配置
1.下载组件
cat > /etc/yum.repos.d/kubernetes.repo <<-EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
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
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
查看安装版本:
yum list kubeadm.x86_64 --showduplicates | sort -r|grep 1.25
下载k8s:
yum -y install kubeadm-1.25.0 kubelet-1.25.0 kubectl-1.25.0
设置开机自启:
systemctl daemon-reload
systemctl enable --now kubelet
检查状态:
systemctl status kubelet (启动异常,异常信息提示初始化 init)
如果启动异常需要进行查看日志:
journalctl -xefu kubelet
2.检查镜像,如果下载慢,使用国产镜像
#k8s提供镜像
[root@k8s-master ~]# kubeadm config images list --kubernetes-version v1.25.0
registry.k8s.io/kube-apiserver:v1.25.0
registry.k8s.io/kube-controller-manager:v1.25.0
registry.k8s.io/kube-scheduler:v1.25.0
registry.k8s.io/kube-proxy:v1.25.0
registry.k8s.io/pause:3.8
registry.k8s.io/etcd:3.5.4-0
registry.k8s.io/coredns/coredns:v1.9.3
#查看国内镜像
[root@k8s-master ~]# kubeadm config images list --image-repository registry.aliyuncs.com/google_containers
registry.aliyuncs.com/google_containers/kube-apiserver:v1.25.0
registry.aliyuncs.com/google_containers/kube-controller-manager:v1.25.0
registry.aliyuncs.com/google_containers/kube-scheduler:v1.25.0
registry.aliyuncs.com/google_containers/kube-proxy:v1.25.0
registry.aliyuncs.com/google_containers/pause:3.8
registry.aliyuncs.com/google_containers/etcd:3.5.4-0
registry.aliyuncs.com/google_containers/coredns:v1.9.3
#下载下来,通过 docker tag 修改进行名称-->registry.k8s.io
例: docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.25.0 registry.k8s.io/kube-apiserver:v1.25.0
3.初始化集群
kubeadm init \
--kubernetes-version=v1.25.0 \
--pod-network-cidr=192.168.0.0/12 \
--service-cidr=10.96.0.0/12 \
--token-ttl=0 --cri-socket unix:///run/cri-dockerd.sock \
--image-repository registry.aliyuncs.com/google_containers \
--ignore-preflight-errors=Swap
#出现下列结果说明成功!
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 10.0.16.4:6443 --token imqv89.0s5moqm9w7996j52 \
--discovery-token-ca-cert-hash sha256:2e0b6250d4fd252c209e275d81b4a20c3b5af466a3512ee134dacfb3f3b000d0
#开始执行上面提示的三条命令:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
4.开启单机污点模式,master可执行调度
提示:如果你是单机,需要开启污点
kubectl taint nodes vm-16-4-centos(节点名称) node-role.kubernetes.io/master-
5.安装网络插件flannel
文章来源:https://www.toymoban.com/news/detail-514177.html
wget https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
# 修改的地方:
net-conf.json: |
{
"Network": "192.168.0.0/24", # 修改为这个值,不然会报错 ,前两位和你的网段一致 init初始化: --pod-network-cidr=192.168.0.0/12
"Backend": {
"Type": "vxlan"
}
}
结束语
本章节完成了,各位正在努力的程序员们,如果你们觉得本文章对您有用的话,或者是你学到了一些东西,希望用您那漂亮,帅气的小手点个赞,支持一下猿仁!
由于工作等原因,更新比较慢,从今天开始,将会持续更新内容!文章来源地址https://www.toymoban.com/news/detail-514177.html
到了这里,关于初始化k8s(启动)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!