Creating a single control-plane cluster with kubeadm
- 1 Initialize the control-plane node
- 2 Installing a Pod network add-on
- 3 Joining the worker node
- 4 Proxying API Server to localhost
- 5 Installing Dashboard
- 5.1 Create Dashboard
- 5.2 권한 부여
- 6 Testing a simple Nginx deployment
- 7 Clean up Node & Control Plane
- 7.1 Reset worker node
- 7.1.1 On worker node:
- 7.1.2 On control plane:
- 7.2 Reset Control Plane
- 7.2.1 On control plane:
- 7.1 Reset worker node
본 페이지에서 쓰이는 Custom K8s object 정의 파일(yaml)은 아래 git repo에서 다운로드 할 수 있다.
Github repo: snetsystems/K8s-Objects
아래 실행 명령어들에는 편의상 sudo와 같은 privilege를 필수 표기하지는 않는다.
실습[운영] 환경에 맞추어 알맞게 실행하도록 한다.
Initialize the control-plane node
kubeadm init [flags]
--apiserver-advertise-address
와 --control-plane-endpoint
옵션(flag)에 대해서는 여기를 참고하며,
이 환경에서는 Flannel network addon을 사용할 것이다.
따라서, --control-plane-endpoint=<Flannel network 대역>
을 지정하며, --apiserver-advertise-address
에 Pod cluster networking을 위해 NAT Network IP로 API server를 지정한다.
참고로, flannel network 대역은 https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml에 지정되어 있으며, 디폴트는 10.244.0.0/16
이다. 만일 호스트에서 사용하는 네트워크 대역과 겹친다면, 겹치지 않도록 지정해야 한다.
위 kube-flannel.yml
파일은 아래 Installing a Pod network add-on 에서 사용된다.
$ kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.20.2.231
...
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 10.20.2.231:6443 --token yii49o.0h5mud78mc6n8x4l \
--discovery-token-ca-cert-hash sha256:88b9c2b032e2cebd057ce7af20e9cb8f1ef283ca87b97f27b56a71f285e4c545
성공하면, 위와 같이 출력되며, 마지막 출력된 지시를 아래와 같이 따르면 된다.
root가 아닌 사용자의 kubectl 사용을 위해 위 출력된 명령을 실행한다.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Installing a Pod network add-on
Pod CNI 네트워크을 위한 Addon을 설치해야 하는데, 여기서는 Flannel를 사용하도록 한다.
위에서 Flannel 및 coredns pod들이 정상적으로 실행(Ready 상태)되는 것을 확인할 수 있다.
Joining the worker node
추가할 노드에 ssh 접속 후, 위에 copy해 둔 명령을 실행한다.
Proxying API Server to localhost
You can now access the API Server locally at curl http://10.20.2.231:8001/api/v1
Installing Dashboard
Create Dashboard
https://github.com/kubernetes/dashboard/releases 에서 원하는 혹은 설치된 k8s control plane 과 호환되는 버전으로 골라서 설치한다. (여기서는 k8s 1.25와 호환되는 v2.7.0
으로 설치한다.)
위 dashboard를 생성하고 나면, k8s cluster 內 모든 노드의 30000번 포트로 접속이 가능할 것이다.
권한 부여
Dashboard의 모든 기능을 사용하기 위해서 적절한 이름의 ServiceAccount를 만들고 cluster admin 권한을 부여하도록 한다.
주의 K8s 1.24부터 SA 생성과 동시에 디폴트 token secret이 자동 생성되지 않음에 유의 바람.
아래와 같이 SA, Token, ClusterRoleBinding을 생성.
https://github.com/snetsystems/K8s-Objects/blob/master/addons/admin-user.yaml
위의 token으로 로그인하면, 모든 기능에 접근 가능할 것이다.
Testing a simple Nginx deployment
테스트를 위해 간단한 Nginx deployment를 해보자.
먼저 아래와 같이 스펙을 작성한다.
https://github.com/snetsystems/K8s-Objects/blob/master/tests/nginx-deployment.yaml
kubectl create -f nginx-deployment.yaml
을 실행한 후, 아래와 같이 k8s-worker01-centos8
, k8s-worker02-centos8
에 nginx가 생성된 것을 확인할 수 있다.
Clean up Node & Control Plane
Ref: Creating a single control-plane cluster with kubeadm: Clean up