관리 메뉴

피터의 개발이야기

[CKA] Udemy 실습문제풀이 - Application Lifecycle Management 본문

Kubernetes/CKA

[CKA] Udemy 실습문제풀이 - Application Lifecycle Management

기록하는 백앤드개발자 2024. 1. 25. 01:22
반응형

 

[kubernetes] 쿠버네티스 관련 글 목차

 

ㅁ 들어가며

ㅇ Udemy, Practice, Application Lifecycle Management 공부 메모.

 

ㅁ 관련 지식

다운워드(Downward) API

 ㄴ 다운워드 API는 컨테이너가 자기 자신 혹은 클러스터에 대한 정보를, 쿠버네티스 클라이언트나 API 서버 없이도 사용할 수 있게 한다.

 

ㅁ secret 생성

 k create secret generic  db-secret --from-literal=DB_Host=sql01 --from-literal=DB_User=root --from-literal=DB_Password=password123 --dry-run=client -o yaml> sec.yaml

 

 

 컨테이너 환경 변수로 사용하기

apiVersion: v1
kind: Pod
metadata:
  name: secret-test-pod
spec:
  containers:
    - name: test-container
      image: registry.k8s.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      envFrom:
      - secretRef:
          name: mysecret
  restartPolicy: Never

 

ㅁ 멀티 컨테이너

# 컨테이너 이름 목록 확인
$ k get po blue -o json | jq .spec.containers

 ㄴ 컨테이너 내용을 확인 할 때는 jq에 인자값을 직접 확인하는 것이 빠름.

 

멀티 컨테이너 생성

$ k run yellow --image busybox --dry-run=client -o yaml   --command -- sleep "1000" > test.yaml

# 최종 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: yellow
  name: yellow
spec:
  containers:
  - command:
    - sleep
    - "1000"
    image: busybox
    name: lemon
  - image: redis
    name: gold

 ㄴ 생성 후 다른 컨테이너를 추가

 

두 개의 컨테이너를 실행하는 파드 생성

apiVersion: v1
kind: Pod
metadata:
  name: app
  namespace: elastic-stack
  labels:
    name: app
spec:
  containers:
  - name: app
    image: kodekloud/event-simulator
    volumeMounts:
    - mountPath: /log
      name: log-volume

  - name: sidecar
    image: kodekloud/filebeat-configured
    volumeMounts:
    - mountPath: /var/log/event-simulator/
      name: log-volume

  volumes:
  - name: log-volume
    hostPath:
      # directory location on host
      path: /var/log/webapp
      # this field is optional
      type: DirectoryOrCreate

 

컨테이너 환경 변수로 사용하기

apiVersion: v1
kind: Pod
metadata:
  name: secret-test-pod
spec:
  containers:
    - name: test-container
      image: registry.k8s.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      envFrom:
      - secretRef:
          name: mysecret
  restartPolicy: Never

 

kibana

Inspect the Kibana UI. You should now see logs appearing in the Discover section.
You might have to wait for a couple of minutes for the logs to populate. You might have to create an index pattern to list the logs. If not sure check this video: https://bit.ly/2EXYdHf

 

ㅁ init 컨테이너

# init container 찾기
# 상세로 각각 찾으면 늦으니 전체 yaml로 받아 vi로 색인이 빠름.
$ k get po -o yaml > tt.log
$ vi tt.log

 

# init 상태 확인, 상세에서 아래 지표 확인
initContainerStatuses
  state:
    terminated:
      reason: Completed

 

# initContainers 갯수
k get po purple -o json | jq .spec.initContainers

 

# init container set-up
---
apiVersion: v1
kind: Pod
metadata:
  name: red
  namespace: default
spec:
  containers:
  - command:
    - sh
    - -c
    - echo The app is running! && sleep 3600
    image: busybox:1.28
    name: red-container
  initContainers:
  - image: busybox
    name: red-initcontainer
    command: 
      - "sleep"
      - "20"

 

# Container logs check
k logs pods/orange init-myservice 
sh: sleeeep: not found

 

ㅁ 함께 보면 좋은 사이트

Certified Kubernetes Administrator(CKA) 자격증 취득 후기

   ㄴ EKS,cdk8s 경험 이야기

 

반응형
Comments