Kubernetes : Configure Control Plane Node2025/11/21 |
|
Configure Multi Nodes Kubernetes Cluster. This example is based on the environment like follows.
-----------+---------------------------+--------------------------+------------
| | |
eth0|10.0.0.30 eth0|10.0.0.51 eth0|10.0.0.52
+----------+-----------+ +-----------+----------+ +-----------+----------+
| [ dlp.srv.world ] | | [ node01.srv.world ] | | [ node02.srv.world ] |
| Control Plane | | Worker Node | | Worker Node |
+----------------------+ +----------------------+ +----------------------+
|
| [1] | |
| [2] | Configure initial setup on Control Plane Node. |
|
[root@dlp ~]# kubeadm config print init-defaults > config.yaml
[root@dlp ~]#
vi config.yaml apiVersion: kubeadm.k8s.io/v1beta4 bootstrapTokens: - groups: - system:bootstrappers:kubeadm:default-node-token token: abcdef.0123456789abcdef ttl: 24h0m0s usages: - signing - authentication kind: InitConfiguration localAPIEndpoint: # change to specify Control Plane Node IP address advertiseAddress: 10.0.0.30 bindPort: 6443 nodeRegistration: # change to specify CRI-O criSocket: unix:///var/run/crio/crio.sock imagePullPolicy: IfNotPresent imagePullSerial: true # change to specify Control Plane Node Hostname name: dlp.srv.world taints: null timeouts: controlPlaneComponentHealthCheck: 4m0s discovery: 5m0s etcdAPICall: 2m0s kubeletHealthCheck: 4m0s kubernetesAPICall: 1m0s tlsBootstrap: 5m0s upgradeManifests: 5m0s --- # add to specify the Hostname or IP address of control Plane Endpoint controlPlaneEndpoint: "10.0.0.30:6443" apiServer: {} apiVersion: kubeadm.k8s.io/v1beta4 caCertificateValidityPeriod: 87600h0m0s certificateValidityPeriod: 8760h0m0s certificatesDir: /etc/kubernetes/pki clusterName: kubernetes controllerManager: {} dns: {} encryptionAlgorithm: RSA-2048 etcd: local: dataDir: /var/lib/etcd imageRepository: registry.k8s.io kind: ClusterConfiguration kubernetesVersion: 1.32.0 networking: dnsDomain: cluster.local serviceSubnet: 10.96.0.0/12 # add to specify the pod network # Calico default is the follows podSubnet: 192.168.0.0/16 proxy: {} scheduler: {} # add follows to switch to the nftables kube-proxy enabled --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 kind: KubeProxyConfiguration mode: nftables[root@dlp ~]# kubeadm init --config=config.yaml
[init] Using Kubernetes version: v1.34.0
[preflight] Running pre-flight checks
[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 beforehand using 'kubeadm config images pull'
[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 [dlp.srv.world kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.0.0.30]
.....
.....
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
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
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/
You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:
kubeadm join 10.0.0.30:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:a0eb7372844a5bf0d31ea23cc30dc27c81fb1e3ce772c49107abbf3a81ecb421 \
--control-plane
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 10.0.0.30:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:a0eb7372844a5bf0d31ea23cc30dc27c81fb1e3ce772c49107abbf3a81ecb421
# set cluster admin user # if you set common user as cluster admin, login with it and run [sudo cp/chown ***] [root@dlp ~]# mkdir -p $HOME/.kube [root@dlp ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config [root@dlp ~]# chown $(id -u):$(id -g) $HOME/.kube/config
|
| [3] | Configure Pod Network with Calico. |
|
[root@dlp ~]# wget https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/operator-crds.yaml [root@dlp ~]# wget https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/tigera-operator.yaml [root@dlp ~]# kubectl apply -f operator-crds.yaml [root@dlp ~]# kubectl apply -f tigera-operator.yaml [root@dlp ~]# cat > custom-resources.yaml <<EOF
apiVersion: operator.tigera.io/v1
kind: Installation
metadata:
name: default
spec:
calicoNetwork:
linuxDataplane: Nftables
ipPools:
- name: default-ipv4-ippool
blockSize: 26
cidr: 192.168.0.0/16
encapsulation: VXLANCrossSubnet
natOutgoing: Enabled
nodeSelector: all()
---
apiVersion: operator.tigera.io/v1
kind: APIServer
metadata:
name: default
spec: {}
EOF
kubectl apply -f custom-resources.yaml installation.operator.tigera.io/default created apiserver.operator.tigera.io/default created # show state : OK if STATUS = Ready [root@dlp ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION dlp.srv.world Ready control-plane 84s v1.34.2 # show state : OK if all are Running [root@dlp ~]# kubectl get pods -A NAMESPACE NAME READY STATUS RESTARTS AGE calico-apiserver calico-apiserver-7b8d565f74-54xmh 1/1 Running 0 69s calico-apiserver calico-apiserver-7b8d565f74-rpzb5 1/1 Running 0 69s calico-system calico-kube-controllers-65599576b-fm6jx 1/1 Running 0 67s calico-system calico-node-9lmfz 1/1 Running 0 67s calico-system calico-typha-666b9d66b6-9nm8z 1/1 Running 0 68s calico-system csi-node-driver-d7nqw 2/2 Running 0 67s kube-system coredns-66bc5c9577-dlv7l 1/1 Running 0 2m18s kube-system coredns-66bc5c9577-zpwwq 1/1 Running 0 2m19s kube-system etcd-dlp.srv.world 1/1 Running 0 2m26s kube-system kube-apiserver-dlp.srv.world 1/1 Running 0 2m26s kube-system kube-controller-manager-dlp.srv.world 1/1 Running 0 2m26s kube-system kube-proxy-zst26 1/1 Running 0 2m19s kube-system kube-scheduler-dlp.srv.world 1/1 Running 0 2m26s tigera-operator tigera-operator-7f579c97c6-5rdzg 1/1 Running 0 82s |
| Sponsored Link |
|
|