本地yum源
安装依赖包
yum install vim wget bash-completion lrzsz nmap nc tree htop iftop net-tools yum-utils device-mapper-persistent-data lvm2 -y
安装软件
yum install docker-ce containerd.io kubelet kubeadm kubectl —disableexcludes=kubernetes -y
systemctl enable —now docker
systemctl enable —now kubelet
百度云盘:
链接:https://pan.baidu.com/s/1uXDIkes2ZoV_GDoDfk_GAA
提取码:lepl
导入docker镜像 11个
docker load -i pause.tar
docker load -i etcd.tar
docker load -i coredns.tar
docker load -i kube-apiserver.tar
docker load -i kube-scheduler.tar
docker load -i kube-controller-manager.tar
docker load -i kube-proxy.tar
docker load -i calico-pod2daemon-flexvo.tar
docker load -i calico-node.tar
docker load -i calico-cni.tar
docker load -i calico-kube-controllers.tar
Master节点
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
liweiming0611/kube-proxy v1.17.0 7d54289267dc 12 days ago 116MB
liweiming0611/kube-controller-manager v1.17.0 5eb3b7486872 12 days ago 161MB
liweiming0611/kube-scheduler v1.17.0 78c190f736b1 12 days ago 94.4MB
liweiming0611/kube-apiserver v1.17.0 0cae8d5cc64c 12 days ago 171MB
calico/node v3.9.4 3b8623e52310 13 days ago 195MB
calico/pod2daemon-flexvol v3.9.4 a29221a9eb60 13 days ago 9.78MB
calico/cni v3.9.4 4b9388dc41e8 13 days ago 167MB
calico/kube-controllers v3.9.4 d35036140573 13 days ago 56MB
liweiming0611/coredns 1.6.5 70f311871ae1 6 weeks ago 41.6MB
liweiming0611/etcd 3.4.3-0 303ce5db0e90 7 weeks ago 288MB
liweiming0611/pause 3.1 da86e6ba6ca1 24 months ago 742kB
[root@master ~]#
集群配置
swapoff -a
sed -i ‘s/.swap./#&/‘ /etc/fstab
sed -i “s/^SELINUX=enforcing/SELINUX=disabled/g” /etc/sysconfig/selinux
sed -i “s/^SELINUX=enforcing/SELINUX=disabled/g” /etc/selinux/config
sed -i “s/^SELINUX=permissive/SELINUX=disabled/g” /etc/sysconfig/selinux
sed -i “s/^SELINUX=permissive/SELINUX=disabled/g” /etc/selinux/config
Docker引擎环境要求:
sudo mkdir -p /etc/docker
cat << EOF > /etc/docker/daemon.json
{
“exec-opts”: [“native.cgroupdriver=systemd”],
“registry-mirrors”: [“https://0[bb06s1q.mirror.aliyuncs.com](http://bb06s1q.mirror.aliyuncs.com/)”],
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “100m”
},
“storage-driver”: “overlay2”,
“storage-opts”: [“overlay2.override_kernel_check=true”]
}
EOF
设置Docker systemd服务
mkdir -p /etc/systemd/system/docker.service.d
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
systemctl daemon-reload && systemctl restart docker containerd
开启内核转发
cat <
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl —system
加载检查 ipvs内核
lsmod | grep ip_vs
modprobe ip_vs
集群初始化
导出kubeadm集群部署自定义文件
kubeadm config print init-defaults > init.default.yaml 导出配置文件
[root@master ~]# cat init.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:
#配置主节点IP信息
advertiseAddress: 192.168.31.147
bindPort: 6443
nodeRegistration:
criSocket: /var/run/dockershim.sock
name: 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: liweiming0611
kind: ClusterConfiguration
kubernetesVersion: v1.17.0
networking:
dnsDomain: cluster.local
#自定义podIP地址段
podSubnet: “192.168.0.0/16”
serviceSubnet: 10.96.0.0/12
scheduler: {}
—-
# 开启 IPVS 模式
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
SupportIPVSProxyMode: true
mode: ipvs
开始部署集群
[root@master ~]# kubeadm init —config=init.default.yaml | tee kubeadm-init.log
W1216 22:53:34.393127 8505 validation.go:28] Cannot validate kube-proxy config - no validator is available
W1216 22:53:34.393322 8505 validation.go:28] Cannot validate kubelet config - no validator is available
[init] Using Kubernetes version: v1.17.0
[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/
[WARNING Hostname]: hostname “master” could not be reached
[WARNING Hostname]: hostname “master”: lookup master on 114.114.114.114:53: no such host
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using ‘kubeadm config images pull’
[kubelet-start] Writing kubelet environment file with flags to file “/var/lib/kubelet/kubeadm-flags.env”
[kubelet-start] Writing kubelet configuration to file “/var/lib/kubelet/config.yaml”
[kubelet-start] Starting the kubelet
[certs] Using certificateDir folder “/etc/kubernetes/pki”
[certs] Generating “ca” certificate and key
[certs] Generating “apiserver” certificate and key
[certs] apiserver serving cert is signed for DNS names [master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.31.147]
[certs] Generating “apiserver-kubelet-client” certificate and key
[certs] Generating “front-proxy-ca” certificate and key
[certs] Generating “front-proxy-client” certificate and key
[certs] Generating “etcd/ca” certificate and key
[certs] Generating “etcd/server” certificate and key
[certs] etcd/server serving cert is signed for DNS names [master localhost] and IPs [192.168.31.147 127.0.0.1 ::1]
[certs] Generating “etcd/peer” certificate and key
[certs] etcd/peer serving cert is signed for DNS names [master localhost] and IPs [192.168.31.147 127.0.0.1 ::1]
[certs] Generating “etcd/healthcheck-client” certificate and key
[certs] Generating “apiserver-etcd-client” certificate and key
[certs] Generating “sa” key and public key
[kubeconfig] Using kubeconfig folder “/etc/kubernetes”
[kubeconfig] Writing “admin.conf” kubeconfig file
[kubeconfig] Writing “kubelet.conf” kubeconfig file
[kubeconfig] Writing “controller-manager.conf” kubeconfig file
[kubeconfig] Writing “scheduler.conf” kubeconfig file
[control-plane] Using manifest folder “/etc/kubernetes/manifests”
[control-plane] Creating static Pod manifest for “kube-apiserver”
W1216 22:53:45.702858 8505 manifests.go:214] the default kube-apiserver authorization-mode is “Node,RBAC”; using “Node,RBAC”
[control-plane] Creating static Pod manifest for “kube-controller-manager”
[control-plane] Creating static Pod manifest for “kube-scheduler”
W1216 22:53:45.704681 8505 manifests.go:214] the default kube-apiserver authorization-mode is “Node,RBAC”; using “Node,RBAC”
[etcd] Creating static Pod manifest for local etcd in “/etc/kubernetes/manifests”
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory “/etc/kubernetes/manifests”. This can take up to 4m0s
[apiclient] All control plane components are healthy after 35.504468 seconds
[upload-config] Storing the configuration used in ConfigMap “kubeadm-config” in the “kube-system” Namespace
[kubelet] Creating a ConfigMap “kubelet-config-1.17” in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see —upload-certs
[mark-control-plane] Marking the node master as control-plane by adding the label “node-role.kubernetes.io/master=’’”
[mark-control-plane] Marking the node master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: abcdef.0123456789abcdef
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[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 192.168.31.147:6443 —token abcdef.0123456789abcdef \
—discovery-token-ca-cert-hash sha256:e0ff59cdbbc63250c342911636604ad9e2fb41d95d07f5850039efd6b38cad4b
集群网络部署
集群节点扩容
Node节点导入的容器镜像:
docker load -i kube-proxy.tar
docker load -i calico-pod2daemon-flexvo.tar
docker load -i calico-node.tar
docker load -i calico-cni.tar
docker load -i calico-kube-controllers.tar
docker load -i pause.tar
[root@node02 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
liweiming0611/kube-proxy v1.17.0 7d54289267dc 12 days ago 116MB
calico/node v3.9.4 3b8623e52310 13 days ago 195MB
calico/pod2daemon-flexvol v3.9.4 a29221a9eb60 13 days ago 9.78MB
calico/cni v3.9.4 4b9388dc41e8 13 days ago 167MB
calico/kube-controllers v3.9.4 d35036140573 13 days ago 56MB
liweiming0611/pause 3.1 da86e6ba6ca1 24 months ago 742kB
[root@node02 docker]#
node节点部署:
**
[root@node02 ~]# kubeadm join 22.144.104.245:6443 —token abcdef.0123456789abcdef \
> —discovery-token-ca-cert-hash