Kubernetes_8

최시열·2023년 2월 9일
0

2023.02.09


9장 레이블과 어노테이션

annotation

cat > annotation.yaml

apiVersion: v1
kind: Pod
metadata:
 name: pod-annotation
 annotations:
   builder: "kwjeon (kwjeon31@gmail.com)"
   buildDate: "20230105"
   imageRegistry: https://hub.docker.com/
spec:
 containers:
 - name: nginx
   image: nginx:1.14
   ports:
   - containerPort: 80

cat > annotation-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx
  annotations:
    kubernetes.io/change-cause: version 1.15
spec:
  progressDeadlineSeconds: 600
  revisionHistoryLimit: 10
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  replicas: 3
  selector:
    matchLabels:
      app: webui
  template:
    metadata:
      labels:
        app: webui
    spec:
      containers:
      - name: web
        image: nginx:1.15
        ports:
        - containerPort: 80

레이블을 이용한 카나리 배포

  • stable version pod 생성
cat > mainui-stable.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mainui-stable
spec:
  replicas: 2
  selector:
    matchLabels:
      app: mainui
      version: stable
  template:
    metadata:
      labels:
        app: mainui
        version: stable
    spec:
      containers:
      - name: mainui
        image: nginx:1.14
        ports:
        - containerPort: 80
  • 묶어주는 service 생성
cat > mainui-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mainui-svc
spec:
  selector:
    app: mainui
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  • canary version pod 생성
cat > mainui-canary.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mainui-canary
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mainui
      version: canary
  template:
    metadata:
      labels:
        app: mainui
        version: canary
    spec:
      containers:
      - name: mainui
        image: nginx:1.15
        ports:
        - containerPort: 80

10장 ConfigMap

환경변수를 지정함에 따라서 pod의 옵션으로 줄수 있다.

  • 디렉토리 구성

  • configmap 생성

kubectl create configmap kube-config --from-literal=INTERVAL=2 --from-literal=OPTION=boy --from-file=config.dir/
  • 생성된 configmap 확인
    kubectl get configmaps kube-config -o wide
    kubectl describe configmaps kube-config

  • genid yaml 파일 생성

cat > genid.yaml

apiVersion: v1
kind: Pod
metadata:
  name: genid-stone
spec:
  containers:
  - image: siyeol/genid:env
    env:
    - name: INTERVAL
      valueFrom:
        configMapKeyRef:
          name: kube-config
          key: INTERVAL
    name: fakeid
    volumeMounts:
    - name: html
      mountPath: /webdata
  - image: nginx:1.14
    name: web-server
    volumeMounts:
    - name: html
      mountPath: /usr/share/nginx/html
      readOnly: true
    ports:
    - containerPort: 80
  volumes:
  - name: html
    emptyDir: {}
  • genid sh 파일 구성
mkdir build
cat > build/genid.sh

#!/bin/bash
mkdir -p /webdata
while true
do
  /usr/bin/rig | /usr/bin/boxes -d $OPTION  > /webdata/index.html
  sleep $INTERVAL
done
  • dockerfile 만들기
cd build
cat > dockerfile

FROM ubuntu:18.04
RUN apt-get update ; apt-get -y install rig boxes
ENV INTERVAL 5
ENV OPTION stone
ADD genid.sh /bin/genid.sh
RUN chmod +x /bin/genid.sh
ENTRYPOINT ["/bin/genid.sh"]
  • docker image 만들기
    docker build .

  • 생성된 이미지에 태그
    docker tag [imageID] genid:env
    docker tag genid:env siyeol/genid:env

  • 이미지 push
    docker push siyeol/genid

  • pod 생성
    kubectl apply -f genid.yaml

  • pod 안으로 들어가기
    kubectl exec -it genid-stone /bin/bash

  • env 명령어로 환경 변수에 따른 pod의 설정값이 잘 지정되었는지 확인 (ex. INTERVAL = 3)

  • 설치한 명령어 (rig, boxes) 확인

profile
최시열

0개의 댓글