On-Primise Kubernets 1.21 구축(VirtualBox or VIRT) - 03. cluster 구성

1. kubernetes 구성 방안

2. Control plane 구성

아래와 같은 명령어로 control plane 서버를 ubuntu2004-001(192.168.122.11) 서버에 구성한다.
 

# kubeadm init --control-plane-endpoint=192.168.122.11:6443

control plane 서버의 IP가 192.168.122.11와 같아 위와 같이 endpoint를 지정해서 구성한다.

# kubeadm init --control-plane-endpoint=192.168.122.11:6443
[init] Using Kubernetes version: v1.24.2
[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 in 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 [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local ubuntu2004-001] and IPs [10.96.0.1 192.168.122.11]
[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 [localhost ubuntu2004-001] and IPs [192.168.122.11 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost ubuntu2004-001] and IPs [192.168.122.11 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
[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
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[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 15.005452 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" 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 ubuntu2004-001 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node ubuntu2004-001 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: 7oszoq.ihl2val82igwttmj
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[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

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 192.168.122.11:6443 --token 7oszoq.ihl2val82igwttmj \
	--discovery-token-ca-cert-hash sha256:a477e2271ea3c6480836b3e07fedb3147769fe6ae825898282880cc0b299754a \
	--control-plane

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.122.11:6443 --token 7oszoq.ihl2val82igwttmj \
	--discovery-token-ca-cert-hash sha256:a477e2271ea3c6480836b3e07fedb3147769fe6ae825898282880cc0b299754a

위와 같이 실행 결과가 뜨면서 정상적으로 control plane이 구성된다.

아래 명령어를 사용해서 kubectl용 접속 파일을 시스템에 저장한다.

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

 

아래는 어딘가 저장해준다. node를 control plane과 연계할 때 사용한다.

kubeadm join 192.168.122.11:6443 --token 7oszoq.ihl2val82igwttmj \
	--discovery-token-ca-cert-hash sha256:a477e2271ea3c6480836b3e07fedb3147769fe6ae825898282880cc0b299754a

 

해당 상태에서 "kubectl get all --all-namespaces", "kubectl get nodes" 확인해보면 아직 node가 붙지 않아서 정상적으로 동작하지
않는다.

root@ubuntu2004-001:~# kubectl get all --all-namespaces
NAMESPACE     NAME                                         READY   STATUS    RESTARTS   AGE
kube-system   pod/coredns-6d4b75cb6d-6h4fd                 0/1     Pending   0          3m21s
kube-system   pod/coredns-6d4b75cb6d-cnnrr                 0/1     Pending   0          3m21s
kube-system   pod/etcd-ubuntu2004-001                      1/1     Running   0          3m25s
kube-system   pod/kube-apiserver-ubuntu2004-001            1/1     Running   0          3m25s
kube-system   pod/kube-controller-manager-ubuntu2004-001   1/1     Running   0          3m25s
kube-system   pod/kube-proxy-h9j8b                         1/1     Running   0          3m21s
kube-system   pod/kube-scheduler-ubuntu2004-001            1/1     Running   0          3m25s

NAMESPACE     NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  3m27s
kube-system   service/kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   3m25s

NAMESPACE     NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/kube-proxy   1         1         1       1            1           kubernetes.io/os=linux   3m25s

NAMESPACE     NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   deployment.apps/coredns   0/2     2            0           3m25s

NAMESPACE     NAME                                 DESIRED   CURRENT   READY   AGE
kube-system   replicaset.apps/coredns-6d4b75cb6d   2         2         0       3m22s




root@ubuntu2004-001:~# kubectl  get nodes
NAME             STATUS     ROLES           AGE    VERSION
ubuntu2004-001   NotReady   control-plane   4m4s   v1.24.2

 

3. node를 control plane에 연결

ubuntu2004-002 ~ ubuntu2004-004 서버에 접속해서 control plane을 초기화하면서 나온 명령어를 사용해서 control plane에 연동한다.

root@ubuntu2004-002:~# kubeadm join 192.168.122.11:6443 --token 7oszoq.ihl2val82igwttmj \
> --discovery-token-ca-cert-hash sha256:a477e2271ea3c6480836b3e07fedb3147769fe6ae825898282880cc0b299754a
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

 

node 현황을 살펴보면 아직 Ready 상태가 아니다.
 

root@ubuntu2004-001:~# kubectl get nodes
NAME             STATUS     ROLES           AGE    VERSION
ubuntu2004-001   NotReady   control-plane   8m8s   v1.24.2
ubuntu2004-002   NotReady   <none>          45s    v1.24.2
ubuntu2004-003   NotReady   <none>          25s    v1.24.2
ubuntu2004-004   NotReady   <none>          21s    v1.24.2

node의 syslog를 살펴보면 아래와 같이 cni plugin이 설치되지 않아서 동작하지 않는다고 나온다.

root@ubuntu2004-002:~# tail -f /var/log/syslog
Jul 12 09:30:49 ubuntu2004-002 kubelet[4044]: E0712 09:30:49.470263    4044 kubelet.go:2349] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized"
Jul 12 09:30:54 ubuntu2004-002 kubelet[4044]: E0712 09:30:54.472733    4044 kubelet.go:2349] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized"

 

4. CNI plugin 설치  - calico

https://kubernetes.io/docs/tasks/administer-cluster/network-policy-provider/calico-network-policy/
위 문서를 읽어서 설치하는 방법을 찾는다. (찾다보면 calico 사이트에서 설치 방법을 찾을 수 있다.)

https://projectcalico.docs.tigera.io/getting-started/kubernetes/self-managed-onprem/onpremises

아래와 같이 calico를 설치한다.

# curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O

# kubectl apply -f calico.yaml

 

설치 후, node나 pod 상태를 보면 모두 정상적으로 실행되는 것을 확인할 수 있다.

root@ubuntu2004-001:~# kubectl get nodes
NAME             STATUS   ROLES           AGE   VERSION
ubuntu2004-001   Ready    control-plane   20m   v1.24.2
ubuntu2004-002   Ready    <none>          13m   v1.24.2
ubuntu2004-003   Ready    <none>          12m   v1.24.2
ubuntu2004-004   Ready    <none>          12m   v1.24.2


root@ubuntu2004-001:~# kubectl get all --all-namespaces
NAMESPACE     NAME                                           READY   STATUS    RESTARTS   AGE
kube-system   pod/calico-kube-controllers-6766647d54-2jdwm   1/1     Running   0          3m4s
kube-system   pod/calico-node-2xq8d                          1/1     Running   0          3m4s
kube-system   pod/calico-node-4ps6b                          1/1     Running   0          3m4s
kube-system   pod/calico-node-b5bp9                          1/1     Running   0          3m4s
kube-system   pod/calico-node-ldpbn                          1/1     Running   0          3m4s
kube-system   pod/coredns-6d4b75cb6d-6h4fd                   1/1     Running   0          20m
kube-system   pod/coredns-6d4b75cb6d-cnnrr                   1/1     Running   0          20m
kube-system   pod/etcd-ubuntu2004-001                        1/1     Running   0          20m
kube-system   pod/kube-apiserver-ubuntu2004-001              1/1     Running   0          20m
kube-system   pod/kube-controller-manager-ubuntu2004-001     1/1     Running   0          20m
kube-system   pod/kube-proxy-c7dmk                           1/1     Running   0          13m
kube-system   pod/kube-proxy-gpwpl                           1/1     Running   0          13m
kube-system   pod/kube-proxy-h9j8b                           1/1     Running   0          20m
kube-system   pod/kube-proxy-pbdwz                           1/1     Running   0          13m
kube-system   pod/kube-scheduler-ubuntu2004-001              1/1     Running   0          20m

NAMESPACE     NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  20m
kube-system   service/kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   20m

NAMESPACE     NAME                         DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/calico-node   4         4         4       4            4           kubernetes.io/os=linux   3m4s
kube-system   daemonset.apps/kube-proxy    4         4         4       4            4           kubernetes.io/os=linux   20m

NAMESPACE     NAME                                      READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   deployment.apps/calico-kube-controllers   1/1     1            1           3m4s
kube-system   deployment.apps/coredns                   2/2     2            2           20m

NAMESPACE     NAME                                                 DESIRED   CURRENT   READY   AGE
kube-system   replicaset.apps/calico-kube-controllers-6766647d54   1         1         1       3m4s
kube-system   replicaset.apps/coredns-6d4b75cb6d                   2         2         2       20m

 

 - On-Primise Kubernets 1.21 구축(VirtualBox or VIRT) - 01. 구성 환경
 - On-Primise Kubernets 1.21 구축(VirtualBox or VIRT) - 02. 시스템 설정
 - On-Primise Kubernets 1.21 구축(VirtualBox or VIRT) - 04. metalLB 구성