K8s 公网部署集群
BackGroud
在公网环境下,或者需要跨局域网组成集群下。需要让Master以公网IP启动,而kubeadm init 参数启动,只支持局域网。
Deploy
- 获取配置文件
kubead config default > k8s-init.yaml
,localAPIEndpoint.advertiseAddress
就是公网IP地址
最新使用 kubeadm config print init-defaults > k8s-init.yaml
apiVersion: kubeadm.k8s.io/v1beta2 bootstrapTokens: - groups: - system:bootstrappers:kubeadm:default-node-token token: abcdef.0123456789abcdef ttl: 24h0m0s usages: - signing - authenticationi kind: InitConfiguration localAPIEndpoint: advertiseAddress: 121.36.210.8 bindPort: 6443 nodeRegistration: criSocket: /var/run/dockershim.sock 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 extraArgs: listen-client-urls: "https://127.0.0.1:2379,https://127.0.0.1:2379" listen-peer-urls: "https://127.0.0.1:2380" imageRepository: registry.aliyuncs.com/google_containers kind: ClusterConfiguration kubernetesVersion: v1.21.14 networking: dnsDomain: cluster.local serviceSubnet: 10.96.0.0/12 podSubnet: 10.244.0.0/16
|
启动集群
kubeadm init --config k8s-init.yaml
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
查看是否正确,cat /root/.kube/config
,的IP和配置文件。