Kubeadm离线部署k8s集群
Kubeadm离线部署k8s集群系统初始化一、安装所需的docker、kube三剑客、设置proxykube-proxy开启ipvs的前置条件(所有节点)modprobe br_netfiltercat > /etc/sysconfig/modules/ipvs.modules << EOF#!/bin/bashmodprobe -- ip_vsmodprobe...
Kubeadm离线部署k8s集群
一、安装所需的docker、kube三剑客、设置proxy
kube-proxy开启ipvs的前置条件(所有节点)
modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules << EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs
安装docker(所有节点)
yum install -y yum-utils device-mapper-persistent-data lvm2 git
本地的yum源可以解决依赖包
这些要在有网的机器上做
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce -y
离线安装 用yum解决依赖关系
yum -y install containerd.io-1.2.10-3.2.el7.x86_64.rpm docker-ce-19.03.5-3.el7.x86_64.rpm container-selinux-2.107-1.el7_6.noarch.rpm docker-ce-cli-19.03.5-3.el7.x86_64.rpm
systemctl enable docker
systemctl restart docker
mkdir /etc/docker
cat > /etc/docker/daemon.json << EOF
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
systemctl daemon-reload
systemctl restart docker
安装kubeadm(所有节点)
1、有线
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
yum makecache fast -y
yum install -y kubelet-1.15.1 kubeadm-1.15.1 kubectl-1.15.1
2、离线
去 kubernetes、base目录里找rpm包
用yum解决不用排列顺序
yum -y install 1yum -y install 14bfe6e75a9efc8eca3f638eb22c7e2ce759c67f95b43b16fae4ebabde1549f3-cri-tools-1.13.0-0.x86_64.rpm \
548a0dcd865c16a50980420ddfa5fbccb8b59621179798e6dc905c9bf8af3b34-kubernetes-cni-0.7.5-0.x86_64.rpm \
aa386b8f2cac67415283227ccb01dc043d718aec142e32e1a2ba6dbd5173317b-kubeadm-1.15.1-0.x86_64.rpm \
f27b0d7e1770ae83c9fce9ab30a5a7eba4453727cdc53ee96dc4542c8577a464-kubectl-1.15.1-0.x86_64.rpm \
f5edc025972c2d092ac41b05877c89b50cedaa7177978d9e5e49b5a2979dbc85-kubelet-1.15.1-0.x86_64.rpm \
socat-1.7.3.2-2.el7.x86_64.rpm
systemctl enable kubelet && systemctl restart kubelet
二、初始化(master节点)
生成kubeadm-config.yaml文件
kubeadm config print init-defaults > kubeadm-config.yaml
vim kubeadm-config.yaml
修改
本机ip
k8s的版本
Nod和pod的地址段
初始化语句
kubeadm init --config=kubeadm-config.yaml --experimental-upload-certs |tee kubeadm-init.log
***
上面那个语句不行,再用下面这个
***
kubeadm init --config=kubeadm-config.yaml --upload-certs |tee kubeadm-init.log
出来这个就是成功了
初始化信息保存到了kubeadm-init.log文件里,没保存也不用慌
rm -rf $HOME/.kube
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
重置初始化
kubeadm reset
rm -rf /var/lib/cni/ $HOME/.kube/config
配置flannel.yml
下载kube-flannel.yml文件
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
这是 flannel 11版
需要在kube-flannel.yml中使用–iface参数指定集群主机内网网卡的名称,否则可能会出现dns无法解析。容器无法通信的情况,需要将kube-flannel.yml下载到本地,
flanneld启动参数加上–iface=<iface-name>\
containers:
- name: kube-flannel
image: registry.cn-shanghai.aliyuncs.com/gcr-k8s/flannel:v0.10.0-amd64
command:
- /opt/bin/flanneld
args:
- --ip-masq
- --kube-subnet-mgr
- --iface=eth0 (添加)
使flannel文件生效
kubectl apply -f kube-flannel.yml
成功了, 是有flannel这块网卡的
以ipvs模式 运行kube-proxy
这段我借鉴的大佬的
kubectl edit cm kube-proxy -n kube-system
[root@master] ~$ kubectl edit cm kube-proxy -n kube-system
configmap/kube-proxy edited
#修改如下
kind: MasterConfiguration
apiVersion: kubeadm.k8s.io/v1alpha1
...
ipvs:
excludeCIDRs: null
minSyncPeriod: 0s
scheduler: ""
syncPeriod: 30s
kind: KubeProxyConfiguration
metricsBindAddress: 127.0.0.1:10249
mode: "ipvs" #修改
...
之后重启(删除proxy节点)各个节点上的kube-proxy(删除后会自动重新创建)
kubectl get pod -n kube-system | grep kube-proxy |awk '{system("kubectl delete pod "$1" -n kube-system")}'
kubectl get pod -n kube-system | grep kube-proxy
node节点加入master节点
这加入的命令是初始化时生成的。
!!!别copy我这个,下面一条 加节点命令是初始化的时候生成的~~~!!!
kubeadm join x.x.x.x:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:91d74a72460e197dc9c88ce57c2d8b6e4ad2a789108b3d0779f6a3a1c4063230
查看:
kubectl get noyum tem
kubectl get service
kubectl get svc --namespace kube-system
更多推荐
所有评论(0)