k8s集群部署-centos
一、docker配置
1.安装docker
略
2.修改docker配置
对 Docker 的配置做一点修改,在“/etc/docker/daemon.json”里把 cgroup 的驱动程序改成 systemd ,然后重启 Docker 的守护进程
cat <<EOF | sudo tee /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2" } EOF sudo systemctl enable docker sudo systemctl daemon-reload sudo systemctl restart docker
二、修改iptables
修改 iptables 的配置,启用“br_netfilter”模块:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf br_netfilter EOF cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward=1 # better than modify /etc/sysctl.conf EOF #加载配置 sudo sysctl --system
三、关闭 Linux 的 swap 分区
sudo swapoff -a sudo sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
四、安装kubeadm
1.配置k8s的源
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 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF #关闭selinux防火墙 setenforce 0 #查看kubeadm可用版本 yum list kubeadm --showduplicates -y | sort -r #安装指定版本kubeadm yum install -y kubelet-1.23.3-0 kubeadm-1.23.3-0 kubectl-1.23.3-0 #yum install -y kubelet kubeadm kubectl systemctl enable kubelet && systemctl start kubelet
2.查看版本
安装完成之后,你可以验证版本是否正确:
kubeadm version kubectl version --client
3.查看安装 Kubernetes 所需的镜像列表,
参数 --kubernetes-version 可以指定版本号
kubeadm config images list --kubernetes-version v1.23.3 #输出 k8s.gcr.io/kube-apiserver:v1.23.3 k8s.gcr.io/kube-controller-manager:v1.23.3 k8s.gcr.io/kube-scheduler:v1.23.3 k8s.gcr.io/kube-proxy:v1.23.3 k8s.gcr.io/pause:3.6 k8s.gcr.io/etcd:3.5.1-0 k8s.gcr.io/coredns/coredns:v1.8.6
但这些镜像在Google自己的镜像仓库gcr,国内从gcr可能拉不下来,可以从阿里云拉,但需要改名,使用一个shell脚本来完成,事实证明,还挺好用
repo=registry.aliyuncs.com/google_containers for name in `kubeadm config images list --kubernetes-version v1.23.3`; do src_name=${name#k8s.gcr.io/} src_name=${src_name#coredns/} docker pull $repo/$src_name docker tag $repo/$src_name $name docker rmi $repo/$src_name done
4.初始化
#apiserver-advertise-address是本机ip sudo kubeadm init \ --pod-network-cidr=10.244.0.0/16 \ --apiserver-advertise-address=10.200.6.239 \ --kubernetes-version=v1.23.3
输出
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.200.6.239:6443 --token 3okkc7.s1k9csdgirqi0ehj \ --discovery-token-ca-cert-hash sha256:bf039aee7c9988ec551a141409c1edf157a1ef6e0699b18cdec419384b489e46
需要执行mkdir那三条命令,kubeadm join保存下来
5.安装网络插件flannel
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
稍等一会,在看kubectl get node,就发现状态status变成ready了。
这样master就按照安好了!
6.安装worker
安装worker只需要在worker上执行如下命令,成功发现worker就可以了
kubeadm join 10.200.6.239:6443 --token 3okkc7.s1k9csdgirqi0ehj \ --discovery-token-ca-cert-hash sha256:bf039aee7c9988ec551a141409c1edf157a1ef6e0699b18cdec419384b489e46 #在master执行,如果发现了worker节点,就是成功了 kubectl get nodes
标签:centos,kubernetes,--,集群,io,kubeadm,k8s,name From: https://www.cnblogs.com/wangbin2188/p/17119256.html