본문 바로가기

⭐ Kubernetes & EKS/EKS

EKS 점검사항

728x90
반응형

1) 쿠버네티스 pod 로그보기

명령어 : kubectl logs [#pod name], kubectl logs -f [#pod name]

- kubectl get pod 명령어를 통해 pod NAME 을 확인할 수 있습니다.

ec2-user:~/environment/yaml $ kubectl get pod
NAME                                                        READY   STATUS    RESTARTS   AGE
deploy-jenkins-6996c6559c-2q9sl                             1/1     Running   0          42m
deploy-jenkins-6996c6559c-68d4w                             1/1     Running   0          42m
deploy-jenkins-6996c6559c-wrjnf                             1/1     Running   0          42m
nginx-ingress-1633598365-controller-9fd8986dc-6jd6s         1/1     Running   0          5h19m
nginx-ingress-1633598365-default-backend-6b6986bdf8-rvz5d   1/1     Running   0          5h19m

- pod 로그를 확인하기 위해서는 kubectl logs [#pod name] 명령어를 통해 로그를 볼 수 있습니다.

ec2-user:~/environment/yaml $ kubectl logs deploy-jenkins-6996c6559c-2q9sl
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-07 14:00:55.781+0000 [id=1]     INFO    org.eclipse.jetty.util.log.Log#initialized: Logging initialized @3329ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-10-07 14:00:56.400+0000 [id=1]     INFO    winstone.Logger#logInternal: Beginning extraction from war file
2021-10-07 14:01:01.586+0000 [id=1]     WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2021-10-07 14:01:02.188+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecfa3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 11.0.12+7
2021-10-07 14:01:03.743+0000 [id=1]     INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-10-07 14:01:03.865+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2021-10-07 14:01:03.865+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2021-10-07 14:01:03.868+0000 [id=1]     INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2021-10-07 14:01:07.029+0000 [id=1]     INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-07 14:01:08.075+0000 [id=1]     INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@3f92a84e{Jenkins v2.303.2,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2021-10-07 14:01:08.146+0000 [id=1]     INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@62452cc9{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-10-07 14:01:08.146+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: Started @15702ms
2021-10-07 14:01:08.159+0000 [id=23]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2021-10-07 14:01:09.967+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2021-10-07 14:01:10.175+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/var/jenkins_home/war/WEB-INF/lib/guice-4.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-10-07 14:01:16.144+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2021-10-07 14:01:16.195+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2021-10-07 14:01:16.296+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2021-10-07 14:01:20.951+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2021-10-07 14:01:20.952+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2021-10-07 14:01:20.953+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-10-07 14:01:20.953+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2021-10-07 14:01:22.762+0000 [id=42]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2021-10-07 14:01:22.883+0000 [id=42]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2021-10-07 14:01:25.336+0000 [id=29]    INFO    jenkins.install.SetupWizard#init: 

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

f86f8fc265d445e6adf30bca6ea6c0bb

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2021-10-07 14:02:29.985+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2021-10-07 14:02:30.061+0000 [id=22]    INFO    hudson.WebAppMain$3#run: Jenkins is fully up and running
2021-10-07 14:02:30.838+0000 [id=42]    INFO    h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2021-10-07 14:02:30.842+0000 [id=42]    INFO    hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2021-10-07 14:02:30.845+0000 [id=42]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Download metadata. 68,070 ms

- kubectl logs -f [#pod name], -f 옵셥을 추가하여 로그를 확인하기, -f 옵션을 주면 실시간으로 업데이트 되는 내역을 확인 가능

ec2-user:~/environment $ kubectl get pod
NAME                                                        READY   STATUS      RESTARTS   AGE
deploy-jenkins-6996c6559c-2q9sl                             1/1     Running     0          7h57m
deploy-jenkins-6996c6559c-68d4w                             1/1     Running     0          7h57m
deploy-jenkins-6996c6559c-wrjnf                             1/1     Running     0          7h57m
hello-1633643460-txnn4                                      0/1     Completed   0          2m43s
hello-1633643520-qtbtp                                      0/1     Completed   0          103s
hello-1633643580-bjsgb                                      0/1     Completed   0          43s
jenkins-9df675f7-27rsv                                      1/1     Running     0          7h7m
jenkins-9df675f7-b99f2                                      1/1     Running     0          7h7m
jenkins-9df675f7-gf2zz                                      1/1     Running     0          7h7m
nginx-ingress-1633598365-controller-9fd8986dc-6jd6s         1/1     Running     0          12h
nginx-ingress-1633598365-default-backend-6b6986bdf8-rvz5d   1/1     Running     0          12h
ec2-user:~/environment $ kubectl logs -f deploy-jenkins-6996c6559c-2q9sl
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-07 14:00:55.781+0000 [id=1]     INFO    org.eclipse.jetty.util.log.Log#initialized: Logging initialized @3329ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-10-07 14:00:56.400+0000 [id=1]     INFO    winstone.Logger#logInternal: Beginning extraction from war file
2021-10-07 14:01:01.586+0000 [id=1]     WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2021-10-07 14:01:02.188+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecfa3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 11.0.12+7
2021-10-07 14:01:03.743+0000 [id=1]     INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-10-07 14:01:03.865+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2021-10-07 14:01:03.865+0000 [id=1]     INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2021-10-07 14:01:03.868+0000 [id=1]     INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2021-10-07 14:01:07.029+0000 [id=1]     INFO    hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-07 14:01:08.075+0000 [id=1]     INFO    o.e.j.s.handler.ContextHandler#doStart: Started w.@3f92a84e{Jenkins v2.303.2,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2021-10-07 14:01:08.146+0000 [id=1]     INFO    o.e.j.server.AbstractConnector#doStart: Started ServerConnector@62452cc9{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-10-07 14:01:08.146+0000 [id=1]     INFO    org.eclipse.jetty.server.Server#doStart: Started @15702ms
2021-10-07 14:01:08.159+0000 [id=23]    INFO    winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2021-10-07 14:01:09.967+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Started initialization
2021-10-07 14:01:10.175+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Listed all plugins
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/var/jenkins_home/war/WEB-INF/lib/guice-4.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-10-07 14:01:16.144+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2021-10-07 14:01:16.195+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Started all plugins
2021-10-07 14:01:16.296+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2021-10-07 14:01:20.951+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: System config loaded
2021-10-07 14:01:20.952+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: System config adapted
2021-10-07 14:01:20.953+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-10-07 14:01:20.953+0000 [id=29]    INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2021-10-07 14:01:22.762+0000 [id=42]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Download metadata
2021-10-07 14:01:22.883+0000 [id=42]    INFO    hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2021-10-07 14:01:25.336+0000 [id=29]    INFO    jenkins.install.SetupWizard#init: 

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

f86f8fc265d445e6adf30bca6ea6c0bb

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2021-10-07 14:02:29.985+0000 [id=28]    INFO    jenkins.InitReactorRunner$1#onAttained: Completed initialization
2021-10-07 14:02:30.061+0000 [id=22]    INFO    hudson.WebAppMain$3#run: Jenkins is fully up and running
2021-10-07 14:02:30.838+0000 [id=42]    INFO    h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2021-10-07 14:02:30.842+0000 [id=42]    INFO    hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2021-10-07 14:02:30.845+0000 [id=42]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Download metadata. 68,070 ms
2021-10-07 14:57:17.278+0000 [id=66]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-10-07 14:57:17.280+0000 [id=66]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 0 ms
2021-10-07 15:57:17.278+0000 [id=74]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-10-07 15:57:17.279+0000 [id=74]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 0 ms
2021-10-07 16:57:17.278+0000 [id=82]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-10-07 16:57:17.282+0000 [id=82]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 1 ms
2021-10-07 17:57:17.278+0000 [id=90]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-10-07 17:57:17.279+0000 [id=90]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 1 ms
2021-10-07 18:57:17.278+0000 [id=98]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-10-07 18:57:17.279+0000 [id=98]    INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 1 ms
2021-10-07 19:57:17.278+0000 [id=106]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-10-07 19:57:17.279+0000 [id=106]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 1 ms
2021-10-07 20:18:35.349+0000 [id=114]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Fingerprint cleanup
2021-10-07 20:18:35.352+0000 [id=114]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Fingerprint cleanup. 2 ms
2021-10-07 20:57:17.278+0000 [id=115]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2021-10-07 20:57:17.279+0000 [id=115]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic background build discarder. 1 ms

2) 쿠버네티스 replica 늘리기

- replica를 늘리기위해서는 먼저 deployment를 확인해봐야 합니다.

명령어 : kubectl get deploy or kubectl get deployment

- jenkins 라고 명시된 서비스를 relicas 3개로 올려보도록 하겠습니다.

ec2-user:~/environment/yaml $ kubectl get deployment
NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deploy-jenkins                             3/3     3            3           49m
http-go                                    0/0     0            0           2d5h
jenkins                                    0/0     0            0           2d2h
nginx-ingress-1633598365-controller        1/1     1            1           5h25m
nginx-ingress-1633598365-default-backend   1/1     1            1           5h25m
ec2-user:~/environment/yaml $

- 명령어 : kubectl scale deploy [#조회된 deploy name] --replicas=복제 수

- kubectl scale deploy jenkins --replicas=3

ec2-user:~/environment/yaml $ kubectl scale deploy jenkins --replicas=3
deployment.apps/jenkins scaled

- kubectl get pod 명령어로 jenkins 의 pod 수가 3개로 늘어난것을 확인할 수 있습니다.

ec2-user:~/environment/yaml $ kubectl get pod
NAME                                                        READY   STATUS    RESTARTS   AGE
deploy-jenkins-6996c6559c-2q9sl                             1/1     Running   0          53m
deploy-jenkins-6996c6559c-68d4w                             1/1     Running   0          53m
deploy-jenkins-6996c6559c-wrjnf                             1/1     Running   0          53m
jenkins-9df675f7-27rsv                                      1/1     Running   0          2m37s
jenkins-9df675f7-b99f2                                      1/1     Running   0          2m37s
jenkins-9df675f7-gf2zz                                      1/1     Running   0          2m37s
nginx-ingress-1633598365-controller-9fd8986dc-6jd6s         1/1     Running   0          5h29m
nginx-ingress-1633598365-default-backend-6b6986bdf8-rvz5d   1/1     Running   0          5h29m
ec2-user:~/environment/yaml $

3) 쿠버네티스 노드 늘리기

- AWS 에서의 노드를 늘리는 방법에 대해서 알아보겠습니다.

- 기본적으로 AWS 노드는 EC2 인스턴스 1대를 의미합니다.

- 아래의 이미지의 경로로 이동하여 노드의 수를 늘리거나 줄일수 있습니다.

- 또한 오토스케일링 그룹에서도 동일하게 노드의 숫자를 늘리거나 줄일수 있습니다.
- 오토스케일링 그룹에서 노드의 수를 조정하게되면 인스턴스 타입도 설정 가능합니다.

- 명령어를 통해 늘리기

eksctl scale nodegroup --cluster=[#클러스터 이름] --nodes=5 --nodes-max 5 --name=[#노드그룹 이름]
eksctl scale nodegroup --cluster=eksworkshop-eksctl-02 --nodes=5 --nodes-max 5 --name=nodegroup

4) 쿠버네티스 노드 모니터링하기

- 쿠버네티스 모니터링은 기본적으로 top 명령어를 통해 모니터링 할 수 있습니다.

- 그라파나 & 프로메테우스 등과 연계하여 모니터링 할 수 있으나, 추가적인 작업이 필요 합니다.

- top 명령어를 통해 node와 pod의 리소스를 모니터링하는 간단한 작업을 확인해 봅시다.

명령어 : kubectl top nodes & kubectl top pod

- 노드는 AWS에서 하나의 인스턴스 입니다.

ec2-user:~/environment/yaml $ kubectl top nodes
NAME                                               CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
ip-192-168-84-12.ap-northeast-2.compute.internal   48m          2%     1157Mi          16%       
ip-192-168-9-245.ap-northeast-2.compute.internal   87m          4%     2327Mi          32%       
ec2-user:~/environment/yaml $

- kubectl top pod 으로 pod가 사용하는 리소스를 확인 할 수 있습니다.

ec2-user:~/environment/yaml $ kubectl top pod
NAME                                                        CPU(cores)   MEMORY(bytes)   
deploy-jenkins-6996c6559c-2q9sl                             1m           269Mi           
deploy-jenkins-6996c6559c-68d4w                             1m           274Mi           
deploy-jenkins-6996c6559c-wrjnf                             1m           280Mi           
jenkins-9df675f7-27rsv                                      1m           271Mi           
jenkins-9df675f7-b99f2                                      1m           296Mi           
jenkins-9df675f7-gf2zz                                      1m           283Mi           
nginx-ingress-1633598365-controller-9fd8986dc-6jd6s         2m           65Mi            
nginx-ingress-1633598365-default-backend-6b6986bdf8-rvz5d   1m           4Mi             
ec2-user:~/environment/yaml $

5) 크론잡 비활성화하기

크론잡 이란?
리눅스의 crontab 처럼 쿠버네티스의 CronJob은 예약 시간마다 특정 포드를 시작해 작업을 수행합니다.

예약 시간
예약 실행 시간은 기존 리눅스 시스템의 크론에서 표기하는 방법과 동일합니다. 각 다음 내용을 의미하며 숫자로 표기합니다. CronJob yaml 파일에는 예약 실행할 시간과 실행할 컨테이너를 작성해야 합니다. 일반적으로 CronJob 하나에 하나의 작업 실행을 권장합니다. 
┌───────────── 분 (0 - 59)
│ ┌───────────── 시 (0 - 23)
│ │ ┌───────────── 일 (1 - 31)
│ │ │ ┌───────────── 월 (1 - 12)
│ │ │ │ ┌───────────── 요일 (0 - 6) 일요일(0)부터 토요일까지(6)
│ │ │ │ │ 
│ │ │ │ │
│ │ │ │ │
* * * * * 
- *을 표기하는 경우에는 매분을 의미한다.
- 반복적인 시간에는 */3과 같은 형태로 선언하면 3으로 나누어 떨어지는 모든 숫자를 의미한다.

- 크론잡 조회하기

- kubectl get cronjob [#jobname] 를 통해 현재 생성된 cronjob의 조회가 가능합니다.

ec2-user:~/environment $ kubectl get cronjob
NAME    SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
hello   */1 * * * *   False     0        <none>          16s
ec2-user:~/environment $

- 크론잡 비 활성화 : kubectl delete cronjob [#jobname] 을 통해 비활성화? 삭제? 가 가능합니다.

ec2-user:~/environment $ kubectl delete cronjob hello
cronjob.batch "hello" deleted
ec2-user:~/environment $

6) 크론잡 활성화하기

- 크론잡의 활성화는 다시 생성을 해주면 됩니다.

ec2-user:~/environment $ kubectl create -f cronjob.yaml
cronjob.batch/hello created
ec2-user:~/environment $

- 실행 확인

ec2-user:~/environment $ kubectl get cronjob
NAME    SCHEDULE      SUSPEND   ACTIVE   LAST SCHEDULE   AGE
hello   */1 * * * *   False     1        13s             24s
ec2-user:~/environment $

7) (ALB)인그레스 로그 활성화

쿠버네티스에서의 인그레스 란?

쿠버네티스의 Ingress는 외부에서 쿠버네티스 클러스터 내부로 들어오는 네트워크 요청,
즉, Ingress 트래픽을 어떻게 처리할지 정의한다.

728x90
반응형