在CentOS下配置Kubernetes(k8s)网络涉及多个步骤,以下是详细的配置指南:
/etc/sysconfig/network-scripts/ifcfg-ens33
。BOOTPROTO
为 static
,ONBOOT
为 yes
。DEVICE=ens33
BOOTPROTO=static
IPADDR=192.168.8.106
NETMASK=255.255.255.0
GATEWAY=192.168.8.1
DNS1=8.8.8.8
DNS2=8.8.4.4
ONBOOT=yes
systemctl restart network
hostnamectl
命令设置每台机器的主机名。hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
/etc/hosts
文件,为每个节点配置主机名。192.168.8.106 k8s-master
192.168.8.107 k8s-node1
192.168.8.108 k8s-node2
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUXenforcing/SELINUXdisabled/' /etc/selinux/config
systemctl start chronyd
systemctl enable chronyd
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
kubectl apply -f pod.yaml
kubectl exec -it test-pod -- /bin/sh
ping 192.168.8.107
通过以上步骤,您可以在CentOS上成功配置Kubernetes集群的网络。根据具体需求选择合适的网络插件,并确保网络插件正确安装和配置,以实现集群内部和外部的通信畅通。