Exercise 5.3: Using ConfigMaps Configure Ambassador Containers

  1. PV 생성

    cat <<EOF | kubectl create -f -
    kind: PersistentVolume
    apiVersion: v1
    metadata:
      name: weblog-pv-volume
      labels:
        type: local
    spec:
      capacity:
        storage: 100Mi
      accessModes:
        - ReadWriteOnce
      hostPath:
        path: "/tmp/weblog"
    EOF
  2. 생성된 PV 확인

    kubectl get pv weblog-pv-volume
  3. PVC 생성

    cat <<EOF | kubectl create -f -
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: weblog-pv-claim
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 100Mi
    EOF
  4. 생성된 PVC 확인

    kubectl get pvc weblog-pv-claim
  5. Pod 생성

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        type: webserver
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: "/var/log/nginx/"
          name: weblog-pv-storage
      - name: fdlogger
        image: fluent/fluentd
        volumeMounts:
        - mountPath: "/var/log"
          name: weblog-pv-storage
      volumes:
      - name: weblog-pv-storage
        persistentVolumeClaim:
          claimName: weblog-pv-claim
    EOF
  6. Pod가 생성된 노드 확인

    kubectl get pod nginx -o wide
  7. Pod 생성된 노드에 접속해서 hostPath에 명시한 디렉토리가 생성됐는지 확인

    ls -al /tmp/weblog/
  8. CP 노드로 이동

  9. CURL 명령어를 통해서 생성된 Pod의 IP주소로 HTTP 요청

    for i in {1..5}
    do
    curl -sI $(kubectl get pod nginx -o=jsonpath='{.status.podIP}')
    done
  10. Pod 접속해서 로그파일 확인

    {
        kubectl exec nginx -it -c nginx -- ls -al /var/log/nginx
        kubectl exec nginx -it -c nginx -- cat /var/log/nginx/access.log
    }
  11. Pod 생성된 노드에 접속해서 로그파일 확인

    cat /tmp/weblog/access.log
  12. CP 노드로 이동

  13. Fluentd 컨테이너 로그 확인

    kubectl logs nginx -c fdlogger
  14. ConfigMap 생성

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: fluentd-config
    data:
      fluentd.conf: |
        <source>
          @type tail
          format none
          path /var/log/access.log
          tag count.format1
        </source>
    
        <match *.**>
        @type stdout
        id stdout_output
        </match>
    EOF
  15. Pod 삭제

    kubectl delete pod nginx
  16. Pod 생성

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        type: webserver
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: "/var/log/nginx/"
          name: weblog-pv-storage
      - name: fdlogger
        image: fluent/fluentd
        env:
        - name: FLUENTD_OPT
          value: -c /etc/fluentd-config/fluentd.conf
        volumeMounts:
        - mountPath: "/var/log"
          name: weblog-pv-storage
        - name: log-config
          mountPath: "/etc/fluentd-config"
      volumes:
      - name: weblog-pv-storage
        persistentVolumeClaim:
          claimName: weblog-pv-claim
      - name: log-config
        configMap:
          name: fluentd-config
    EOF
  17. CURL 명령어를 통해서 생성된 Pod의 IP주소로 HTTP 요청

    for i in {1..5}
    do
    curl -sI $(kubectl get pod nginx -o=jsonpath='{.status.podIP}')
    done
  18. Fluentd 컨테이너 로그 확인

    kubectl logs nginx -c fdlogger
  19. 리소스 삭제

    {
        kubectl delete pod nginx
        kubectl delete cm fluentd-config
        kubectl delete pvc weblog-pv-claim
        kubectl delete pv weblog-pv-volume
    }

Last updated