brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Feb 15. 2023

1. 오라클 클라우드 - 쿠버네티스 -시작하기

<1> 쿠버네티스 시작하기

<2> pod 생성과 삭제

<3> deployment 삭제와 생성

<4> 개인 정리


<1> 쿠버네티스 시작하기




1

Oracle Cloud.

Cloud Shell로 쿠버네티스 사용해보자.



2

api-resources 보자
topasvga@cloudshell:~ (ap-seoul-1)$ kubectl api-resources
NAME                              SHORTNAMES   APIVERSION                             NAMESPACED   KIND
bindings                                       v1                                     true         Binding
componentstatuses   cs           v1                                     false        :

:

clusterroles                                   rbac.authorization.k8s.io/v1           false        ClusterRole
rolebindings                                rbac.authorization.k8s.io/v1           true         RoleBinding
roles                                          rbac.authorization.k8s.io/v1           true         Role
priorityclasses                   pc           scheduling.k8s.io/v1                   false        PriorityClass
csidrivers                                     storage.k8s.io/v1                      false        CSIDriver
csinodes                                       storage.k8s.io/v1                      false        CSINode
csistoragecapacities                   storage.k8s.io/v1                 true         CSIStorageCapacity
storageclasses    sc           storage.k8s.io/v1   false        StorageClass
volumeattachments           storage.k8s.io/v1                    false        VolumeAttachment



3

네임 스페이스 보자.

디폴트 , kube-node, 퍼블릭, 시스템 이 있네요~


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get namespaces
NAME              STATUS   AGE
default           Active   17h
kube-node-lease   Active   17h
kube-public       Active   17h
kube-system       Active   17h



4

만들어진 노드 보자.

워커 노드가 2개가 있다.


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get nodes
NAME          STATUS   ROLES   AGE   VERSION
10.0.10.141   Ready    node    17h   v1.25.4
10.0.10.80    Ready    node    17h   v1.25.4



5

클러스터 정보 보자~


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl cluster-info
Kubernetes control plane is running at https://152.70.232.60:6443
CoreDNS is running at https://152.70.232.60:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.


6

노드 kube-system에 있는 파드를 보자~


topasvga@cloudshell:~ (ap-seoul-1)$ kubectl get pod -n kube-system
NAME                                   READY   STATUS    RESTARTS      AGE
coredns-6f5cb65d87-7xc4b               1/1     Running   0             17h
coredns-6f5cb65d87-x9wt5               1/1     Running   0             17h

csi-oci-node-8mnf4                     1/1     Running   0             17h
csi-oci-node-h6f5j                     1/1     Running   0             17h
kube-dns-autoscaler-6d666b855c-bmp42   1/1     Running   0             17h
kube-flannel-ds-9lnvp                  1/1     Running   1 (17h ago)   17h
kube-flannel-ds-cc9mx                  1/1     Running   1 (17h ago)   17h
kube-proxy-7ltz2                       1/1     Running   0             17h
kube-proxy-tbf25                       1/1     Running   0             17h
proxymux-client-bq95h                  1/1     Running   0             17h
proxymux-client-vcszw                  1/1     Running   0             17h



7

Prompt 변경 툴 설치  (선택)


topasvga@cloudshell:~ (ap-seoul-1)$ git clone https://github.com/jonmosco/kube-ps1.git
Cloning into 'kube-ps1'...
remote: Enumerating objects: 638, done.
remote: Counting objects: 100% (73/73), done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 638 (delta 42), reused 52 (delta 25), pack-reused 565
Receiving objects: 100% (638/638), 7.25 MiB | 5.18 MiB/s, done.
Resolving deltas: 100% (336/336), done.


8

프롬프트 변경하기 (선택)


topasvga@cloudshell:~ (ap-seoul-1)$ vim .bashrc


topasvga@cloudshell:~ (ap-seoul-1)$ more .bashrc-backup
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
source /etc/bashrc.cloudshell



9

변경

맨아래  source /etc/bashrc.cloudshell  대신

source ~/kube-ps1/kube-ps1.sh

PS1='[\u@\h:\w $(kube_ps1)]\$ '

KUBE_PS1_SYMBOL_ENABLE=false


topasvga@cloudshell:~ (ap-seoul-1)$ source ~/.bashrc


[topasvga@e752e0f6b962:~ (context-c2lqg34zlva:N/A)]$ sed -i "s/kubernetes-admin@kubernetes/kube/g" ~/.kube/config


[topasvga@e752e0f6b962:~ (context-c2lqg34zlva:N/A)]$ kubeoff

[topasvga@e752e0f6b962:~ ]$ kubeon
[topasvga@e752e0f6b962:~ (context-c2lqg34zlva:N/A)]$

[topasvga@e752e0f6b962:~ (context-c2lqg34zlva:N/A)]$ kubeoff



10

node 정보 보기

[topasvga@e752e0f6b962]$ kubectl get nodes
NAME          STATUS   ROLES   AGE   VERSION
10.0.10.141   Ready    node    17h   v1.25.4
10.0.10.80    Ready    node    17h   v1.25.4


11

node정보 상세 보기
[topasvga@e752e0f6b962]$ kubectl get nodes -o wide
NAME          STATUS   ROLES   AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                  KERNEL-VERSION                      CONTAINER-RUNTIME
10.0.10.141   Ready    node    17h   v1.25.4   10.0.10.141   <none>        Oracle Linux Server 8.6   5.4.17-2136.314.6.2.el8uek.x86_64   cri-o://1.25.1-111.el8
10.0.10.80    Ready    node    17h   v1.25.4   10.0.10.80    <none>        Oracle Linux Server 8.6   5.4.17-2136.314.6.2.el8uek.x86_64   cri-o://1.25.1-111.el8



12

전체 pod 보기

[topasvga@e752e0f6b962]$ kubectl get pod --all-namespaces
NAMESPACE     NAME                                   READY   STATUS    RESTARTS      AGE
default       deployment-2048-8445476958-6w4nk       1/1     Running   0             8h
default       deployment-2048-8445476958-tw72c       1/1     Running   0             8h

kube-system   coredns-6f5cb65d87-7xc4b               1/1     Running   0             17h
kube-system   coredns-6f5cb65d87-x9wt5               1/1     Running   0             17h
kube-system   csi-oci-node-8mnf4                     1/1     Running   0             17h
kube-system   csi-oci-node-h6f5j                     1/1     Running   0             17h
kube-system   kube-dns-autoscaler-6d666b855c-bmp42   1/1     Running   0             17h
kube-system   kube-flannel-ds-9lnvp                  1/1     Running   1 (17h ago)   17h
kube-system   kube-flannel-ds-cc9mx                  1/1     Running   1 (17h ago)   17h
kube-system   kube-proxy-7ltz2                       1/1     Running   0             17h
kube-system   kube-proxy-tbf25                       1/1     Running   0             17h
kube-system   proxymux-client-bq95h                  1/1     Running   0             17h
kube-system   proxymux-client-vcszw                  1/1     Running   0             17h





<2> pod 생성과 삭제


1

기존 pod 확인

[topasvga@e752e0f6b962]$ kubectl get pod
NAME                               READY   STATUS    RESTARTS   AGE
deployment-2048-8445476958-6w4nk   1/1     Running   0          8h
deployment-2048-8445476958-tw72c   1/1     Running   0          8h



2

nginx 이미지로 myweb1 pod 만들어보기


[topasvga@e752e0f6b962]$ kubectl run myweb1 --image nginx
pod/myweb1 created



[topasvga@e752e0f6b962]$ kubectl run myweb2 --image nginx && kubectl get pod -w

pod/myweb2 created
NAME                               READY   STATUS              RESTARTS   AGE
deployment-2048-8445476958-6w4nk   1/1     Running             0          8h
deployment-2048-8445476958-tw72c   1/1     Running             0          8h
myweb1                             1/1     Running             0          13s
myweb2                             0/1     ContainerCreating   0          2s


myweb2                             1/1     Running             0          12s


3

pod 보기

[topasvga@e752e0f6b962]$ kubectl get pod
NAME                               READY   STATUS    RESTARTS   AGE
deployment-2048-8445476958-6w4nk   1/1     Running   0          8h
deployment-2048-8445476958-tw72c   1/1     Running   0          8h
myweb1                             1/1     Running   0          37s
myweb2                             1/1     Running   0          26s



4

pod 정보 상세 보기 - ip정보까지보기

[topasvga@e752e0f6b962]$ kubectl get pod -o wide
NAME                               READY   STATUS    RESTARTS   AGE   IP             NODE          NOMINATED NODE   READINESS GATES
deployment-2048-8445476958-6w4nk   1/1     Running   0          8h    10.244.0.4     10.0.10.80    <none>           <none>
deployment-2048-8445476958-tw72c   1/1     Running   0          8h    10.244.0.132   10.0.10.141   <none>           <none>
myweb1                             1/1     Running   0          65s   10.244.0.5     10.0.10.80    <none>           <none>
myweb2                             1/1     Running   0          54s   10.244.0.133   10.0.10.141   <none>           <none>




[topasvga@e752e0f6b962]$ ping 10.244.0.5
Ping is not supported in Cloud Shell



[topasvga@e752e0f6b962]$ curl 10.244.0.5
안됨



5

pod 지우기

[topasvga@e752e0f6b962]$ kubectl delete pod myweb1
pod "myweb1" deleted


[topasvga@e752e0f6b962]$ kubectl delete pod myweb2
pod "myweb2" deleted





<3> deployment 삭제와 생성


1

deployment 확인

[topasvga@e752e0f6b962]$ kubectl get deploy,replicasets,pods
NAME                              READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/deployment-2048   2/2     2            2           9h

NAME                                         DESIRED   CURRENT   READY   AGE
replicaset.apps/deployment-2048-8445476958   2         2         2       9h

NAME                                   READY   STATUS    RESTARTS   AGE
pod/deployment-2048-8445476958-6w4nk   1/1     Running   0          9h
pod/deployment-2048-8445476958-tw72c   1/1     Running   0          9h



2

삭제

[topasvga@e752e0f6b962]$ kubectl delete deploy deployment-2048
deployment.apps "deployment-2048" deleted

[topasvga@e752e0f6b962]$ kubectl get deploy,replicasets,pods
No resources found in default namespace.



3

커서 변경

[topasvga@e752e0f6b962:~ (context-c2lqg34zlva:N/A)]$ kubeoff
[topasvga@e752e0f6b962:~ ]$
[topasvga@e752e0f6b962:~ ]$



4

deployment 를 사용하는 이유를 알아보자.

원하는 상태를 유지한다.


[topasvga@e752e0f6b962:~ ]$ kubectl get pods
No resources found in default namespace.


5

deployment로 pod 3개를 만든다.
[topasvga@e752e0f6b962:~ ]$ kubectl create deployment my-webs --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --replicas=3
deployment.apps/my-webs created


[topasvga@e752e0f6b962:~ ]$ kubectl get pods
NAME                       READY   STATUS              RESTARTS   AGE
my-webs-6fc5987f47-hrr5r   0/1     ContainerCreating   0          5s
my-webs-6fc5987f47-kcztw   0/1     ContainerCreating   0          5s
my-webs-6fc5987f47-zm6ks   0/1     ContainerCreating   0          5s



6

상세히 보자
[topasvga@e752e0f6b962:~ ]$ kubectl get pod -o wide
NAME                       READY   STATUS    RESTARTS   AGE   IP             NODE          NOMINATED NODE   READINESS GATES
my-webs-6fc5987f47-hrr5r   1/1     Running   0          58s   10.244.0.6     10.0.10.80    <none>           <none>
my-webs-6fc5987f47-kcztw   1/1     Running   0          58s   10.244.0.134   10.0.10.141   <none>           <none>
my-webs-6fc5987f47-zm6ks   1/1     Running   0          58s   10.244.0.7     10.0.10.80    <none>           <none>


7

6개 pod로 변경해 보자.

[topasvga@e752e0f6b962:~ ]$ kubectl scale --current-replicas=3 --replicas=6 deployment/my-webs

deployment.apps/my-webs scaled

[topasvga@e752e0f6b962:~ ]$ kubectl get pod -o wide

NAME                       READY   STATUS    RESTARTS   AGE   IP             NODE          NOMINATED NODE   READINESS GATES
my-webs-6fc5987f47-2p4kq   1/1  Running   0    3s    10.244.0.8   10.0.10.80  <none>  <none>
my-webs-6fc5987f47-4xrc4  1/1  Running  0  3s   10.244.0.135  10.0.10.141  <none>  <none>
my-webs-6fc5987f47-hrr5r   1/1  Running   0  83s  10.244.0.6  10.0.10.80 <none>  <none>
my-webs-6fc5987f47-kcztw  1/1  Running   0  83s  10.244.0.134  10.0.10.141  <none> <none>
my-webs-6fc5987f47-mlwk6   1/1 Running  0  3s  10.244.0.136   10.0.10.141   <none><none>
my-webs-6fc5987f47-zm6ks   1/1 Running   0   83s   10.244.0.7 10.0.10.80 <none>   <none>


8

Pod 1개를 지워보자~

[topasvga@e752e0f6b962:~ ]$ kubectl delete pod my-webs-6fc5987f47-2p4kq
pod "my-webs-6fc5987f47-2p4kq" deleted

[topasvga@e752e0f6b962:~ ]$ kubectl get pod -o wide
NAME                       READY   STATUS        RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES
my-webs-6fc5987f47-2p4kq   1/1 Terminating 0  71s  10.244.0.8 10.0.10.80    <none> <none>
my-webs-6fc5987f47-4xrc4   1/1  Running   0  71s 10.244.0.135   10.0.10.141 <none><none>
my-webs-6fc5987f47-hrr5r   1/1  Running   0  2m31s   10.244.0.6 10.0.10.80  <none> <none>
my-webs-6fc5987f47-kcztw  1/1 Running 0  2m31s 10.244.0.134  10.0.10.141 <none> <none>
my-webs-6fc5987f47-mlwk6  1/1    Running 0 71s 10.244.0.136   10.0.10.141 <none>  <none>
my-webs-6fc5987f47-vfzlv  1/1    Running 0 17s     10.244.0.9     10.0.10.80   <none>  <none>
my-webs-6fc5987f47-zm6ks  1/1  Running 0 31s   10.244.0.7     10.0.10.80  <none>   <none>




8

pod 1개는 종료되었지만, 6개를 유지한다.  신규로 자동으로 1개가 생긴다.


[topasvga@e752e0f6b962:~ ]$ kubectl get pod -o wide
NAME                       READY   STATUS    RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES
my-webs-6fc5987f47-4xrc4   1/1     Running   0          88s     10.244.0.135   10.0.10.141   <none>           <none>
my-webs-6fc5987f47-hrr5r   1/1     Running   0          2m48s   10.244.0.6     10.0.10.80    <none>           <none>
my-webs-6fc5987f47-kcztw   1/1     Running   0          2m48s   10.244.0.134   10.0.10.141   <none>           <none>
my-webs-6fc5987f47-mlwk6   1/1     Running   0          88s     10.244.0.136   10.0.10.141   <none>           <none>
my-webs-6fc5987f47-vfzlv   1/1     Running   0          34s     10.244.0.9     10.0.10.80    <none>           <none>
my-webs-6fc5987f47-zm6ks   1/1     Running   0          2m48s   10.244.0.7     10.0.10.80    <none>           <none>
[topasvga@e752e0f6b962:~ ]$



9

pod를 1개로 줄여 보자


[topasvga@e752e0f6b962:~ ]$ kubectl scale --current-replicas=6 --replicas=1 deployment/my-webs
deployment.apps/my-webs scaled



5개는 종료 중이다.~
[topasvga@e752e0f6b962:~ ]$ kubectl get pod -o wide
NAME                       READY   STATUS        RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES
my-webs-6fc5987f47-4xrc4   1/1     Terminating   0          7m13s   10.244.0.135   10.0.10.141   <none>           <none>
my-webs-6fc5987f47-hrr5r   1/1     Terminating   0          8m33s   10.244.0.6     10.0.10.80    <none>           <none>
my-webs-6fc5987f47-kcztw   1/1     Terminating   0          8m33s   10.244.0.134   10.0.10.141   <none>           <none>
my-webs-6fc5987f47-mlwk6   1/1     Running       0          7m13s   10.244.0.136   10.0.10.141   <none>           <none>
my-webs-6fc5987f47-vfzlv   1/1     Terminating   0          6m19s   10.244.0.9     10.0.10.80    <none>           <none>
my-webs-6fc5987f47-zm6ks   1/1     Terminating   0          8m33s   10.244.0.7     10.0.10.80    <none>           <none>




Pod 5개가 종료 되었다.

원하는 데로 1개만 남았다.


[topasvga@e752e0f6b962:~ ]$ kubectl get pod -o wide
NAME                       READY   STATUS    RESTARTS   AGE     IP             NODE          NOMINATED NODE   READINESS GATES
my-webs-6fc5987f47-mlwk6   1/1     Running   0          7m42s   10.244.0.136   10.0.10.141   <none>           <none>



10

모든 pod를 없애려면 어떻게 하나?

deploymentf를 지워야 한다.


[topasvga@e752e0f6b962:~ ]$ kubectl get deploy,pods
NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/my-webs   3/3     3            3           32s

NAME                           READY   STATUS    RESTARTS   AGE
pod/my-webs-6fc5987f47-mrqj4   1/1     Running   0          32s
pod/my-webs-6fc5987f47-nktzb   1/1     Running   0          32s
pod/my-webs-6fc5987f47-xfzdw   1/1     Running   0          32s



[topasvga@e752e0f6b962:~ ]$ kubectl delete deployments.apps my-webs
deployment.apps "my-webs" deleted


[topasvga@e752e0f6b962:~ ]$ kubectl get deploy,pods

No resources found in default namespace.




<4> 개인 정리


1

Oracle Cloud는 1달은 무료로 쿠버네티스 실습하기 좋다 ~

kubectl 명령어들이 잘 된다.


2

프롬프트 변경은 Oracle Cloud 재시작하면  node를 못불러 온다.

프롬프트 변경은 사용하지 말자. Cloud Shell을 원복하자.


감사합니다.

브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari