kind (Kubernetes in Docker)를 사용하여 kubernetes 클러스터 구축

kind란?



Kubernetes in Docker의 약어로 Docker 컨테이너를 복수개 기동해, 그 컨테이너를 KubernetesNode로서 이용하는 것으로, 복수대 구성의 Kubernetes 클러스터를 구축한다.

만들 환경



다음과 같은 환경(Master 1대, Worker 1대의 KubernetesCluster를 1대)을 작성한다.
※VPS 계약하지 않아도 Mac이나 Windows의 로컬로 할 수 있다고 생각됩니다.


사용한 환경의 버전 정리


[root@xxxxxxxx ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

[root@xxxxxxxx ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.1
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        831ebea
 Built:             Tue Dec 15 04:37:17 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.1
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       f001486
  Built:            Tue Dec 15 04:35:42 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

[root@xxxxxxxx ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.2", GitCommit:"52c56ce7a8272c798dbc29846288d7cd9fbae032", GitTreeState:"clean", BuildDate:"2020-06-03T04:00:21Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

[root@xxxxxxxx ~]# kind version
kind v0.7.0 go1.13.6 linux/amd64

1. 초기 설정, 설치



1-1. VPS 초기 설정(보안상의 이유 등으로 필요한 경우)



· 사용자 작성
・sshd 주위의 설정(root 로그인 금지 등)
・증명서 배치
etc...

1-2. Docker 설치



(※참고 URL)[ htps : // 이 m / y 마사오카 / ms / b6c3 000000 ]

1-3. kubectl 설치 [※참고 URL]( htps:// / ch-b b. 시오 s. jp/아 r



chmod +x ./kubectl
mv ./kubectl/usr/local/bin/
ls -l/usr/local/bin/kubectl
kubectl 버전
※이하 에러 나오지만 무시
 The connection to the server localhost:8080 was refused - did you specify the right host or port?

1-4. kind 의 인스톨 [※참고 URL]( htps:// / ch ぁ b. 시오 s.



curl -Lo ./kind "htps : // 기주 b. 코 m / 쿠베 r 네 s s gs / Kin d / Ree Ase s / Do wn a d / v0.7.0 / Kin d - $ "
chmod +x ./kind
mv ./kind/usr/local/bin/
ls -l/usr/local/bin/kind
kind version

2. 단일 노드(Master 1대 구성)의 kubernetes 클러스터 작성



2-1. kubernetes 클러스터 작성 명령 실행


[root@xxxxxxxx ~]# kind create cluster

Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.17.0) 🖼 
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Thanks for using kind! 😊

2-2. 확인


[root@xxxxxxxx ~]# docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS         PORTS                       NAMES
9cc673f1e968   kindest/node:v1.17.0   "/usr/local/bin/entr…"   2 minutes ago   Up 2 minutes   127.0.0.1:49157->6443/tcp   kind-control-plane

2-3. 컨텍스트 설정



※컨텍스트를 설정해 지정하는 것으로, kubectl 커멘드의 대상의 kubernetes 클러스터를 지정할 수 있다
[root@xxxxxxxx ~]# kubectl cluster-info --context kind-kind
Kubernetes master is running at https://127.0.0.1:49157
KubeDNS is running at https://127.0.0.1:49157/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

2-4. kubernetes 클러스터 시작 확인


[root@xxxxxxxx ~]# kubectl get node
NAME                 STATUS   ROLES    AGE     VERSION
kind-control-plane   Ready    master   5m58s   v1.17.0

2-5. kubernetes 클러스터 삭제


[root@xxxxxxxx ~]# kind delete cluster
Deleting cluster "kind" ...
[root@xxxxxxxx ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@xxxxxxxx ~]# kubectl get node
The connection to the server localhost:8080 was refused - did you specify the right host or port?

3. 다중 노드(Master 1대, Worker1대 구성)의 kubernetes 클러스터 작성



3-1. yaml 파일 작성



※apiVersion,image의 버젼이 맞지 않으면 실패한다

kind.yaml
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
  image: kindest/node:v1.18.2
- role: worker
  image: kindest/node:v1.18.2

3-2. kubernetes 클러스터 작성 명령 실행


[root@xxxxxxxx ~]# kind create cluster --config kind.yaml --name kindclluster
Creating cluster "kindclluster" ...
 ✓ Ensuring node image (kindest/node:v1.18.2) 🖼
 ✓ Preparing nodes 📦 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Joining worker nodes 🚜 
Set kubectl context to "kind-kindclluster"
You can now use your cluster with:

kubectl cluster-info --context kind-kindclluster

Have a nice day! 👋

3-3. 확인


[root@xxxxxxxx ~]# docker ps -a
CONTAINER ID   IMAGE                  COMMAND                  CREATED              STATUS              PORTS                       NAMES
bc55874ac1ff   kindest/node:v1.18.2   "/usr/local/bin/entr…"   About a minute ago   Up About a minute                               kindclluster-worker
57fd25bbbeba   kindest/node:v1.18.2   "/usr/local/bin/entr…"   About a minute ago   Up About a minute   127.0.0.1:49158->6443/tcp   kindclluster-control-plane

[root@xxxxxxxx ~]# kubectl get nodes
NAME                         STATUS   ROLES    AGE   VERSION
kindclluster-control-plane   Ready    master   72s   v1.18.2
kindclluster-worker          Ready    <none>   37s   v1.18.2

3-4. kubernetes 클러스터 삭제


[root@xxxxxxxx ~]# kind delete cluster
Deleting cluster "kind" ...
[root@xxxxxxxx ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@xxxxxxxx ~]# kubectl get node
The connection to the server localhost:8080 was refused - did you specify the right host or port?

4. nginxpod 배포


kubectl create deployment nginx --image=nginx
kubectl create service nodeport nginx --tcp=8080:80 service/nginx created
kubectl port-forward --address localhost svc/nginx 8080:8080 
curl 127.0.0.1:8080

이상

좋은 웹페이지 즐겨찾기