=================
== The Archive ==
=================

[그림과 실습으로 배우는 쿠버네티스 입문] 4장. 쿠버네티스 클러스터 위에 애플리케이션 만들기

|

cover.jpg

4.1 쿠버네티스 클러스터 위에 애플리케이션 실행하기

4.1.1 리소스의 사양을 담은 매니페스트

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - name: nginx
      image: nginx:latest
      ports:
        - containerPort: 80

4.1.2 컨테이너를 실행하기 위한 최소 구성 리소스: Pod

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - name: nginx
      image: nginx:latest
      ports:
        - containerPort: 80

4.1.3 리소스가 만들어지는 공간: 네임스페이스

flowchart LR
    subgraph ControlPlane[컨트롤 플레인]
        APIServer[kube-apiserver]
        Scheduler[kube-scheduler]
        ControllerManager[kube-controller-manager]
        ETCD[(etcd)]

        ETCD --> APIServer
        Scheduler --> APIServer
        ControllerManager --> APIServer
    end

    subgraph WorkerNode[워커 노드]
        Kubelet[kubelet]
        KubeProxy[kube-proxy]
        Runtime[컨테이너 런타임]

        Kubelet --> Runtime
        Runtime --> C1[컨테이너 😊]
        Runtime --> C2[컨테이너 😊]
    end

    kubectlClient[kubectl 클라이언트 😺] --> APIServer
    APIServer --> Kubelet
    APIServer --> KubeProxy
1
kubectl get pod --namespace kube-system
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
~                                                                                                                                                        21:45:02
❯ minikube start 
😄  minikube v1.37.0 on Darwin 15.6.1 (arm64)
✨  Automatically selected the docker driver. Other choices: qemu2, ssh
📌  Using Docker Desktop driver with root privileges
👍  Starting "minikube" primary control-plane node in "minikube" cluster
🚜  Pulling base image v0.0.48 ...
🔥  Creating docker container (CPUs=2, Memory=2899MB) ...
🐳  Preparing Kubernetes v1.34.0 on Docker 28.4.0 ...
🔗  Configuring bridge CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

~                                                                                                                                                    24s 21:45:33
❯ kubectl get pod --namespace kube-system
NAME                               READY   STATUS    RESTARTS   AGE
coredns-66bc5c9577-fl8lb           1/1     Running   0          85s
etcd-minikube                      1/1     Running   0          91s
kube-apiserver-minikube            1/1     Running   0          91s
kube-controller-manager-minikube   1/1     Running   0          91s
kube-proxy-spck9                   1/1     Running   0          86s
kube-scheduler-minikube            1/1     Running   0          91s
storage-provisioner                1/1     Running   0          90s
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
~                                                                                                                                                        21:00:19
❯ kind create cluster
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.34.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

Have a nice day! 👋

~                                                                                                                                                     9s 21:42:04
❯ kubectl get pod --namespace kube-system
NAME                                         READY   STATUS    RESTARTS   AGE
coredns-66bc5c9577-66xqx                     1/1     Running   0          89s
coredns-66bc5c9577-vz6vc                     1/1     Running   0          89s
etcd-kind-control-plane                      1/1     Running   0          97s
kindnet-chsnc                                1/1     Running   0          89s
kube-apiserver-kind-control-plane            1/1     Running   0          97s
kube-controller-manager-kind-control-plane   1/1     Running   0          97s
kube-proxy-wnmkm                             1/1     Running   0          89s
kube-scheduler-kind-control-plane            1/1     Running   0          97s

4.2 [만들기] Pod 만들기

4.2.1 준비: Pod를 만들기 전에 쿠버네티스 클러스터가 준비되었는지 확인하기

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
~                                                                                                                                                    13s 21:49:37
❯ kubectl get pod --namespace kube-system
NAME                                         READY   STATUS    RESTARTS   AGE
coredns-66bc5c9577-jqzqs                     1/1     Running   0          29s
coredns-66bc5c9577-p6755                     1/1     Running   0          29s
etcd-kind-control-plane                      1/1     Running   0          36s
kindnet-bgcx7                                1/1     Running   0          29s
kube-apiserver-kind-control-plane            1/1     Running   0          36s
kube-controller-manager-kind-control-plane   1/1     Running   0          35s
kube-proxy-6ws7d                             1/1     Running   0          29s
kube-scheduler-kind-control-plane            1/1     Running   0          35s

~                                                                                                                                                        21:50:10
❯ kubectl get nodes                      
NAME                 STATUS   ROLES           AGE   VERSION
kind-control-plane   Ready    control-plane   44s   v1.34.0

~                                                                                                                                                        21:50:17
❯ kind get clusters  
kind

4.2.2 매니페스트 사용해 보기

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
apiVersion: v1
kind: Pod
metadata:
  name: hello-world
  labels:
    app: hello-world
spec:
  containers:
    - name: hello-server
      image: hello-server:1.0.0 # chapter-01/hello-server
      imagePullPolicy: IfNotPresent
      ports:
        - containerPort: 8080

4.2.3 매니페스트를 쿠버네티스 클러스터에 적용하기

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                                  22:04:13
❯ kind load docker-image hello-server:1.0.0
Image: "hello-server:1.0.0" with ID "sha256:cab71a3badb9937732db538f866610832d2bf8c5485ec932c98f7ea8cd144013" not yet present on node "kind-control-plane", loading...

~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                                  22:07:46
❯ kubectl get pod --namespace default                      
No resources found in default namespace.

~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                                  22:08:27
❯ kubectl apply --filename chapter-04/hello-world.yaml --namespace default
pod/hello-world created

~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                                  22:08:40
❯ kubectl get pod --namespace default                                     
NAME          READY   STATUS    RESTARTS   AGE
hello-world   1/1     Running   0          50s

~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                                  22:09:30
❯ curl localhost:8080                             
curl: (7) Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server

~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                                  22:09:35
❯ kubectl port-forward pod/hello-world 8080:8080 -n default
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080

Handling connection for 8080
^C%                                                                                                                                                          
~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                         27s 22:11:48
❯ kubectl delete pod hello-world --namespace default       
pod "hello-world" deleted from default namespace
1
2
3
~/gitFolders/build-breaking-fixing-kubernetes master* ⇡                                                                                              22:11:40
❯ curl localhost:8080
Hello, world!%                                                                                                                                                

kubectl run?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
~/gitFolders/build-breaking-fixing-kubernetes master                   14:23:30
❯ kubectl get pods --namespace default                                    
NAME          READY   STATUS    RESTARTS   AGE
hello-world   1/1     Running   0          75s

~/gitFolders/build-breaking-fixing-kubernetes master                   14:24:45
❯ kubectl run another-hello-world --image=hello-server:1.0.0 --namespace default
pod/another-hello-world created

~/gitFolders/build-breaking-fixing-kubernetes master*                  14:41:10
❯ kubectl get pods --namespace default
NAME                  READY   STATUS    RESTARTS   AGE
another-hello-world   1/1     Running   0          45s
hello-world           1/1     Running   0          18m

Categories:

Tags: