概述
环境: centos7 ,ip 10.2.7.212, kubeadm 1.19
省略部分:docker 安装,配置内网 docker registry,kubeadm、kubelet、kubeproxy 安装,直接从 kubeadm 配置、init 开始。
省略部分可以参考 centos7 使用 kubeadm 安装 kubernetes
1、关闭防火墙、selinux
systemctl stop firewalld
setenforce 0
2、关闭 swap
swapoff -a
cp /etc/fstab /etc/fstab-bak
cat /etc/fstab-bak | grep -v swap > /etc/fstab
3、设置主机名
hostnamectl set-hostname k8s-master
4、配置 hosts
修改 /etc/hosts
10.2.7.212 k8s-master
5、修改 sysctl.conf
修改 /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
sysctl -p
查看配置是否生效
sysctl -a |grep net.ipv4.ip_forward
sysctl -a |grep net.bridge.bridge-nf-call-iptables
sysctl -a |grep net.bridge.bridge-nf-call-ip6tables
6、kubeadm 查看默认配置文件
kubeadm config print init-defaults > default.yaml
7、修改配置文件 default.yaml
[root@k8s-master ~]# cat default.yaml
apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 10.2.7.212
bindPort: 6443
nodeRegistration:
criSocket: /var/run/dockershim.sock
name: k8s-master
taints:
- effect: NoSchedule
key: node-role.kubernetes.io/master
---
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
type: CoreDNS
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.19.0
networking:
dnsDomain: cluster.local
serviceSubnet: 10.254.0.0/16
podSubnet: 10.253.0.0/16
scheduler: {}
8、拉取镜像
kubeadm config images pull --config=default.yaml
9、初始化 master 节点
kubeadm init --config=default.yaml
如果 master 节点高可用,需要添加 --upload-certs
kubeadm init --config=default.yaml --upload-certs
或者使用
kubeadm init
--apiserver-advertise-address=10.2.7.212
--pod-network=cidr=10.253.0.0/16
--service-cidr=10.254.0.0/16
--image-repository=docker.io
解决warning
...
[preflight] Running pre-flight checks
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at
https://kubernetes.io/docs/setup/cri/
[preflight] Pulling images required for setting up a Kubernetes cluster
'''
修改 /etc/docker/daemon.json,增加
"exec-opts": ["native.cgroupdriver=systemd"]
重启 docker
systemctl restart docker
重置
kubeadm reset
初始化 master
[root@k8s-master ~]# kubeadm init --config=default.yaml
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
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
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.2.7.212:6443 --token abcdef.0123456789abcdef
--discovery-token-ca-cert-hash sha256:2d1c35a3c7bfa5f54fade5cb28d81700878363b37e7a2bc9c08b13da837af66a
10、添加 node 节点,按照第 9 步 提示 “kubeadm join 10.2.7.212:6443 --token abcdef.0123456789abcdef
--discovery-token-ca-cert-hash ”
参考 centos7 使用 kubeadm 安装 kubernetes
参考文章:
通过kubeadm离线安装k8s集群v1.15
https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/
最后
以上就是独特电源为你收集整理的内网 kubeadm 部署 k8s的全部内容,希望文章能够帮你解决内网 kubeadm 部署 k8s所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复