2022版K8s搭建
最精简适用版,直接上手
·
#安装依赖 yum install -y conntrack ipvsadm ipset jq sysstat iptables.services libseccomp yum-utils device-mapper-persistent-data lvm2 wget
#环境配置 #配置host ####### #关闭防火墙 systemctl stop firewalld && systemctl disable firewalld systemctl start iptables.service systemctl enable iptables.service iptables -F services iptables save #关闭selinux setenforce 0 #关闭swap swapoff -a #配置系统转发 cat <<EOF >/etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system
#配置Docker的yum源 wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo #安装Docker yum install -y docker-ce-18.09.0 docker-ce-cli-18.09.0 containerd.io systemctl start docker && sudo systemctl enable docker #配置k8s源 cat <<EOF >/etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF #安装k8s组件 yum install -y kubelet-1.14.0-0 yum install -y kubeadm-1.14.0-0 kubectl-1.14.0-0 #配置Docker的cgroup cat <<EOF >/etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"] } EOF systemctl enable kubelet && systemctl start kubelet
#查看k8s所需images kubeadm config images list
#!/bin/bash
set -e
#拉取镜像,国内适用阿里源拉取替换,国外可不用
######################################
KUBE_VERSION=v1.14.0
KUBE_PAUSE_VERSION=3.1
ETCD_VERSION=3.3.10
CORE_DNS_VERSION=1.3.1
GCR_URL=k8s.gcr.io
ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers
images=(kube-proxy:"${KUBE_VERSION}"
kube-scheduler:"${KUBE_VERSION}"
kube-controller-manager:"${KUBE_VERSION}"
kube-apiserver:"${KUBE_VERSION}"
pause:"${KUBE_PAUSE_VERSION}"
etcd:"${ETCD_VERSION}"
coredns:"${CORE_DNS_VERSION}")
for imageName in "${images[@]}"; do
docker pull $ALIYUN_URL/"${imageName}"
docker tag $ALIYUN_URL/"${imageName}" $GCR_URL/"${imageName}"
docker rmi $ALIYUN_URL/"${imageName}"
done
#####################################
#查看images docker images #初始化,创建master kubeadm init --kubernetes-version=1.14.0 --apiserver-advertise-address=IP --pod-network-cidr=10.244.0.0/16 | tee /tmp/k8s_init.log #各用户配置 mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config #查看nodes 存在NO ready kubectl get nodes #配置网络 kubectl apply -f https://docs.projectcalico.org/v3.9/manifests/calico.yaml #查看nodes 全部ready kubectl get nodes kubectl get pods --all-namespaces -w
更多推荐
已为社区贡献1条内容
所有评论(0)