使用kubeadm部署k8s_无坑适用版本
一、环境配置
1.1 系统信息
CentOS Linux release 7.6.1810 (Core)
3.10.0-957.27.2.el7.x86_64
2.2 准备环境
a. 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
b. 关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config setenforce 0
c.关闭swap交换分区
echo "vm.swappiness = 0">> /etc/sysctl.conf swapoff -a
d. 开启IPV4流量转发
cat > /etc/sysctl.d/k8s.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF
e. 加载内核模块
modprobe br_netfilter
f.设置repo源
mv /etc/yum.repos.d/* /tmp/ # base repo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # docker repo curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # k8s repo cat > /etc/yum.repos.d/kubernetes.repo << EOF [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 # update cache yum clean all yum makecache yum repolist
g. 安装常用包
yum install vim bash-completion net-tools gcc -y
三、所有节点安装K8S组件
3.1 安装docker/kubeadm/kubelet
# 安装docker yum install docker-ce-18.06.3.ce -y # 添加阿里云仓库加速(最好换成自己的) mkdir -p /etc/docker tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://ahtqbhz9.mirror.aliyuncs.com"] } EOF systemctl daemon-reload systemctl restart docker systemctl enable docker # 安装 kubeadm、kubelet、kubectl yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0 systemctl enable kubelet
3.2 部署Kubernetes Master
# apiserver-advertise-address地址就是master的IP。 kubeadm init --kubernetes-version=1.18.0 \ --apiserver-advertise-address=10.128.143.100 \ --image-repository registry.aliyuncs.com/google_containers \ --service-cidr=10.10.0.0/16 --pod-network-cidr=10.122.0.0/16 mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config
-
--apiserver-advertise-address: 根据实际MASTER IP地址填写
3.3 设置命令补全
source <(kubectl completion bash)
3.4 安装calico网络
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
3.5 检测pod和node
kubectl get pod --all-namespaces
kubectl get node
3.6 使用单节点k8s
kubectl taint nodes --all node-role.kubernetes.io/master-
默认master节点不会调用pod,清除(taint)污点,有(taint)污点的节点不会调用pod
文章摘要:
原文链接:https://how2play.club /archives/使用kubeadm部署k8s