Service_Mesh/Istio

[Istio-1주차] Istio 첫걸음 (실습)

lati-tech 2025. 4. 13. 05:01

1. 환경


  • Istio in action 책: docker desktop, k8s 1.21.1, istio 1.13 (22.02.11 출시된 구 버전으로, istio-proxy init 실패) - Link
  • 스터디 : docker (kind - k8s 1.23.17 ‘23.2.28 - Link) , istio 1.17.8(’23.10.11) - Link

2. 구성


    • Kind(k8s) 구성하여 실습 진행
      • Kind란?: '도커 IN 도커 - docker in docker’ 로 쿠버네티스 클러스터 환경을 구성 - Link
      • 설치 (Windows (WSL2))
        • WSL 2 설치 + Ubuntu 배포판 설치 - Docs설명서
          • 더보기
            ## Powershell 관리자 권한으로 실행
            
            # DISM(배포 이미지 서비스 및 관리) 명령어로 Microsoft-Windows-Subsystem-Linux 기능을 활성화
            dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
            
            # DISM 명령어로 VirtualMachinePlatform 기능을 활성화
            dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
            
            # wsl 설치
            wsl --install
            
            # 기본값 WSL 2 버전 설정
            wsl --set-default-version 2
            
            # wsl 업데이트
            wsl --update

             

            Windows OS 재부팅 후 아래 수행

            ## Powershell 관리자 권한으로 실행
            
            # 설치 가능한 배포판 확인
            wsl --list --online
            
            # Ubuntu 배포판 설치
            wsl --install Ubuntu-24.04
            ...
            Enter new UNIX username: <각자 Ubuntu 사용 계정>
            New password: <해당 계정 암호>
            Retype new password: <해당 계정 암호>
            passwd: password updated successfully
            Installation successful!
            To run a command as administrator (user "root"), use "sudo <command>".
            ---------------------------------------
            # 기본 정보 확인
            hostnamectl
            whoami
            id
            pwd
            
            # apt 업데이트
            sudo apt update 
            sudo apt install jq htop curl wget ca-certificates net-tools -y
            ifconfig eth0
            ping -c 1 8.8.8.8
            
            # 빠져나오기
            $ exit
            ---------------------------------------
            
            # 설치된 배포판 확인
            wsl -l -v
            
            # Ubuntu 재진입
            wsl


        • WSL2(Ubuntu) 에 Docker 설치 - Docs
          • 더보기
            # WSL2 에 Docker 설치 : 아래 스크립트 실행 후 20초 대기하면 스크립트 실행 됨
            curl -fsSL https://get.docker.com -o get-docker.sh
            sudo sh ./get-docker.sh
            ...
            
            # 설치 확인
            docker info
            docker ps
            sudo systemctl status docker
            cat /etc/group | grep docker


        • WSL2 에 kind 및 관리 툴 설치
          • 더보기
            # 기본 사용자 디렉터리 이동
            cd $PWD
            pwd
            
            #
            sudo systemctl stop apparmor && sudo systemctl disable apparmor
            
            # 
            sudo apt update && sudo apt-get install bridge-utils net-tools jq tree unzip kubectx kubecolor -y
            
            # Install Kind
            curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.27.0/kind-linux-amd64
            chmod +x ./kind
            sudo mv ./kind /usr/local/bin/kind
            kind --version
            
            # Install kubectl
            curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
            chmod +x kubectl
            sudo mv ./kubectl /usr/bin
            sudo kubectl version --client=true
            
            # Install Helm
            curl -s https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
            helm version
            
            # Source the completion
            source <(kubectl completion bash)
            echo 'source <(kubectl completion bash)' >> ~/.bashrc
            
            # Alias kubectl to k
            echo 'alias k=kubectl' >> ~/.bashrc
            echo 'complete -o default -F __start_kubectl k' >> ~/.bashrc
            
            # Install Kubeps & Setting PS1
            git clone https://github.com/jonmosco/kube-ps1.git
            echo -e "source $PWD/kube-ps1/kube-ps1.sh" >> ~/.bashrc
            cat <<"EOT" >> ~/.bashrc
            KUBE_PS1_SYMBOL_ENABLE=true
            function get_cluster_short() {
              echo "$1" | cut -d . -f1
            }
            KUBE_PS1_CLUSTER_FUNCTION=get_cluster_short
            KUBE_PS1_SUFFIX=') '
            PS1='$(kube_ps1)'$PS1
            EOT
            
            # .bashrc 적용을 위해서 logout 후 터미널 다시 접속 하자
            exit

             

        • kind 기본 사용 - 클러스터 배포 및 확인
          • 더보기
            # 클러스터 배포 전 확인
            docker ps
            
            # Create a cluster with kind
            kind create cluster
            
            # 클러스터 배포 확인
            kind get clusters
            kind get nodes
            kubectl cluster-info
            
            # 노드 정보 확인
            kubectl get node -o wide
            
            # 파드 정보 확인
            kubectl get pod -A
            kubectl get componentstatuses
            
            # 컨트롤플레인 (컨테이너) 노드 1대가 실행
            docker ps
            docker images
            
            # kube config 파일 확인
            cat ~/.kube/config
            혹은
            cat $KUBECONFIG # KUBECONFIG 변수 지정 사용 시
            
            # nginx 파드 배포 및 확인 : 컨트롤플레인 노드인데 파드가 배포 될까요?
            kubectl run nginx --image=nginx:alpine
            kubectl get pod -owide
            
            # 노드에 Taints 정보 확인
            kubectl describe node | grep Taints
            Taints:             <none>
            
            # 클러스터 삭제
            kind delete cluster
            
            # kube config 삭제 확인
            cat ~/.kube/config
            혹은
            cat $KUBECONFIG # KUBECONFIG 변수 지정 사용 시
          • 클러스터 배포 및 확인
            docker 설치 확인
            kind로 k8s 클러스터 생성 (1.32.2)
            클러스터 배포 확인
            Node&Pod 정보 확인
            Pod 배포 확인
          • krew 설치 - https://krew.sigs.k8s.io/docs/user-guide/setup/install/
        • kind로 k8s 배포
          • 기본 정보 확인
            • 더보기
              # 클러스터 배포 전 확인
              docker ps
              mkdir ~/aews-labs
              cd ~/aews-labs
              
              # Create a cluster with kind : 1.29.14 , 1.30.10 , 1.31.6 , 1.32.2
              kind create cluster --name myk8s --image kindest/node:v1.32.2 --config - <<EOF
              kind: Cluster
              apiVersion: kind.x-k8s.io/v1alpha4
              nodes:
              - role: control-plane
                extraPortMappings:
                - containerPort: 30000
                  hostPort: 30000
                - containerPort: 30001
                  hostPort: 30001
                - containerPort: 30002
                  hostPort: 30002
                - containerPort: 30003
                  hostPort: 30003
                kubeadmConfigPatches:
                - |
                  kind: ClusterConfiguration
                  controllerManager:
                    extraArgs:
                      bind-address: "0.0.0.0"
                  etcd:
                    local:
                      extraArgs:
                        listen-metrics-urls: "http://0.0.0.0:2381"
                  scheduler:
                    extraArgs:
                      bind-address: "0.0.0.0"
                - |
                  kind: KubeProxyConfiguration
                  metricsBindAddress: "0.0.0.0"
              EOF
              
              # 확인
              kind get nodes --name myk8s
              kubens default
              
              # kind 는 별도 도커 네트워크 생성 후 사용 : 기본값 172.18.0.0/16
              docker network ls
              docker inspect kind | jq
              
              # k8s api 주소 확인 : 어떻게 로컬에서 접속이 되는 걸까?
              kubectl cluster-info
              
              # 노드 정보 확인 : CRI 는 containerd 사용
              kubectl get node -o wide
              
              # 파드 정보 확인 : CNI 는 kindnet 사용
              kubectl get pod -A -o wide
              
              # 네임스페이스 확인 >> 도커 컨테이너에서 배운 네임스페이스와 다릅니다!
              kubectl get namespaces
              
              # 컨트롤플레인노드(컨테이너) 확인 : 도커 컨테이너 이름은 myk8s-control-plane
              docker ps
              docker images
              docker exec -it myk8s-control-plane ss -tnlp
              
              # 디버그용 내용 출력에 ~/.kube/config 권한 인증 로드
              kubectl get pod -v6
              
              # kube config 파일 확인 : "server: https://127.0.0.1:YYYYY" 127.0.0.1:Port로 접속 가능을 확인!
              cat ~/.kube/config
              ls -l ~/.kube/config
            • k8s 배포 및 확인
            • 클러스터 및 API 주소 확인
              pod, namespace 확인
              docker 구성요소, port 확인
              디버그의 권한 인증 및 kubeconfig 내 local 설정 확인
            • kube-ops-view
              kube-ops-view

              • 더보기
                # kube-ops-view
                # helm show values geek-cookbook/kube-ops-view
                helm repo add geek-cookbook https://geek-cookbook.github.io/charts/
                helm install kube-ops-view geek-cookbook/kube-ops-view --version 1.2.2 --set service.main.type=NodePort,service.main.ports.http.nodePort=30000 --set env.TZ="Asia/Seoul" --namespace kube-system
                
                # 설치 확인
                kubectl get deploy,pod,svc,ep -n kube-system -l app.kubernetes.io/instance=kube-ops-view
                
                # kube-ops-view 접속 URL 확인 (1.5 , 2 배율) : 아래 접속 주소를 자신의 웹 브라우저에서 접속할 것!
                echo "http://127.0.0.1:30000/#scale=1.5"
                echo "http://127.0.0.1:30000/#scale=2"
            • Pod 추가
              Pod 추가
              Pod 삭제
        • kind: k8s (1.23.17) 배포
          • 더보기
            #
            git clone https://github.com/AcornPublishing/istio-in-action
            cd istio-in-action/book-source-code-master
            pwd # 각자 자신의 pwd 경로
            code .
            
            # 
            kind create cluster --name myk8s --image kindest/node:v1.23.17 --config - <<EOF
            kind: Cluster
            apiVersion: kind.x-k8s.io/v1alpha4
            nodes:
            - role: control-plane
              extraPortMappings:
              - containerPort: 30000 # Sample Application (istio-ingrssgateway)
                hostPort: 30000
              - containerPort: 30001 # Prometheus
                hostPort: 30001
              - containerPort: 30002 # Grafana
                hostPort: 30002
              - containerPort: 30003 # Kiali
                hostPort: 30003
              - containerPort: 30004 # Tracing
                hostPort: 30004
              - containerPort: 30005 # kube-ops-view
                hostPort: 30005
              extraMounts:
              - hostPath: /Users/gasida/Downloads/istio-in-action/book-source-code-master # 각자 자신의 pwd 경로로 설정
                containerPath: /istiobook
            networking:
              podSubnet: 10.10.0.0/16
              serviceSubnet: 10.200.1.0/24
            EOF
            
            # 설치 확인
            docker ps
            
            # 노드에 기본 툴 설치
            docker exec -it myk8s-control-plane sh -c 'apt update && apt install tree psmisc lsof wget bridge-utils net-tools dnsutils tcpdump ngrep iputils-ping git vim -y'
          • 편의성 툴 설치
            • 더보기
              # (옵션) kube-ops-view
              helm repo add geek-cookbook https://geek-cookbook.github.io/charts/
              helm install kube-ops-view geek-cookbook/kube-ops-view --version 1.2.2 --set service.main.type=NodePort,service.main.ports.http.nodePort=30005 --set env.TZ="Asia/Seoul" --namespace kube-system
              kubectl get deploy,pod,svc,ep -n kube-system -l app.kubernetes.io/instance=kube-ops-view
              
              ## kube-ops-view 접속 URL 확인
              open "http://localhost:30005/#scale=1.5"
              open "http://localhost:30005/#scale=1.3"
              
              # (옵션) metrics-server
              helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
              helm install metrics-server metrics-server/metrics-server --set 'args[0]=--kubelet-insecure-tls' -n kube-system
              kubectl get all -n kube-system -l app.kubernetes.io/instance=metrics-server
        • istio 1.17.8 설치 - Docs , Install , profile
          • 더보기
            # myk8s-control-plane 진입 후 설치 진행
            docker exec -it myk8s-control-plane bash
            -----------------------------------
            # 코드 파일들 마운트 확인
            tree /istiobook/ -L 1
            
            # istioctl 설치
            export ISTIOV=1.17.8
            echo 'export ISTIOV=1.17.8' >> /root/.bashrc
            
            curl -s -L https://istio.io/downloadIstio | ISTIO_VERSION=$ISTIOV sh -
            tree istio-$ISTIOV -L 2 # sample yaml 포함
            cp istio-$ISTIOV/bin/istioctl /usr/local/bin/istioctl
            istioctl version --remote=false
            
            # default 프로파일 컨트롤 플레인 배포
            istioctl x precheck # 설치 전 k8s 조건 충족 검사
            istioctl profile list
            istioctl install --set profile=default -y
            ✔ Istio core installed
            ✔ Istiod installed
            ✔ Ingress gateways installed
            ✔ Installation complete
            
            # 설치 확인 : istiod, istio-ingressgateway, crd 등
            kubectl get istiooperators -n istio-system
            NAME              REVISION   STATUS   AGE
            installed-state                       4m49s
            
            kubectl get istiooperators -n istio-system -o yaml
            ...
              spec:
                components:
                  base:
                    enabled: true
                  cni:
                    enabled: false
                  egressGateways:
                  - enabled: false
                    name: istio-egressgateway
                  ingressGateways:
                  - enabled: true
                    name: istio-ingressgateway
                  istiodRemote:
                    enabled: false
                  pilot:
                    enabled: true
                hub: docker.io/istio
                meshConfig:
                  defaultConfig:
                    proxyMetadata: {}
                  enablePrometheusMerge: true
                profile: default
                ...
                  pilot:
                    autoscaleEnabled: true
                    autoscaleMax: 5
                    autoscaleMin: 1
                    configMap: true
                    cpu:
                      targetAverageUtilization: 80
                    deploymentLabels: null
                    enableProtocolSniffingForInbound: true
                    enableProtocolSniffingForOutbound: true
                    env: {}
                    image: pilot
                    keepaliveMaxServerConnectionAge: 30m
                    nodeSelector: {}
                    podLabels: {}
                    replicaCount: 1
                    traceSampling: 1
                  telemetry:
                    enabled: true
                    v2:
                      enabled: true
                      metadataExchange:
                        wasmEnabled: false
                      prometheus:
                        enabled: true
                        wasmEnabled: false
                      stackdriver:
                        configOverride: {}
                        enabled: false
                        logging: false
                        monitoring: false
                        topology: false
            
            
            kubectl get all,svc,ep,sa,cm,secret,pdb -n istio-system
            ...
            NAME                                    READY   STATUS              RESTARTS   AGE
            istio-ingressgateway-58888b4f9b-gv7r9   1/1     Running             0          2m43s
            istiod-78c465d86b-tsd8l                 1/1     Running             0          3m
            ...
            
            kubectl get crd | grep istio.io | sort
            istioctl verify-install # 설치 확인
            
            # 보조 도구 설치
            kubectl apply -f istio-$ISTIOV/samples/addons
            
            #
            kubectl get pod -n istio-system
            NAME                                    READY   STATUS    RESTARTS   AGE
            grafana-67f5ccd9d7-cgkn4                1/1     Running   0          86s
            istio-ingressgateway-58888b4f9b-7t5zj   1/1     Running   0          116s
            istiod-78c465d86b-pvqv6                 1/1     Running   0          2m14s
            jaeger-78cb4f7d4b-d8b88                 1/1     Running   0          86s
            kiali-c946fb5bc-4njln                   1/1     Running   0          86s
            prometheus-7cc96d969f-6ft4s             2/2     Running   0          86s
            
            # 빠져나오기
            exit
            -----------------------------------
            
            #
            kubectl get cm -n istio-system istio -o yaml
            kubectl get cm -n istio-system istio -o yaml | kubectl neat

             

          • 확인
          • /istiobook/ 마운트 확인
            istio 설치 (1.17)
            crd 확인
            addon 설치 (grafana, jaeger, kiali, prometheus)
            addon 설치 확인
        • Istio 서비스 메시에 첫 애플리케이션 배포
          • 더보기
            #
            kubectl create ns istioinaction
            
            # 방법1 : yaml에 sidecar 설정을 추가
            cat services/catalog/kubernetes/catalog.yaml
            docker exec -it myk8s-control-plane istioctl kube-inject -f /istiobook/services/catalog/kubernetes/catalog.yaml
            ...
              - args:
                    - proxy
                    - sidecar
                    - --domain
                    - $(POD_NAMESPACE).svc.cluster.local
                    - --proxyLogLevel=warning
                    - --proxyComponentLogLevel=misc:error
                    - --log_output_level=default:info
                    - --concurrency
                    - "2"
                    env:
                    - name: JWT_POLICY
                      value: third-party-jwt
                    - name: PILOT_CERT_PROVIDER
                      value: istiod
                    - name: CA_ADDR
                      value: istiod.istio-system.svc:15012
                    - name: POD_NAME
                      valueFrom:
                        fieldRef:
                          fieldPath: metadata.name
              ...
                    image: docker.io/istio/proxyv2:1.13.0
                    name: istio-proxy
            
            
            # 방법2 : namespace에 레이블을 추가하면 istiod (오퍼레이터)가 해당 namepsace의 pod spec에 자동으로 sidecar 설정을 주입
            kubectl label namespace istioinaction istio-injection=enabled
            kubectl get ns --show-labels
            
            # 
            kubectl get mutatingwebhookconfiguration
            NAME                         WEBHOOKS   AGE
            istio-revision-tag-default   4          9m24s # 특정 revision의 사이드카 주입 설정 관리
            istio-sidecar-injector       4          9m45s # Istio는 각 애플리케이션 Pod에 Envoy 사이드카 프록시를 자동으로 주입
                                                          ## 네임스페이스나 Pod에 istio-injection=enabled 라벨이 있어야 작동 
            
            kubectl get mutatingwebhookconfiguration istio-sidecar-injector -o yaml
            
            #
            kubectl get cm -n istio-system istio-sidecar-injector -o yaml | kubectl neat
          • 레이블로 추가함.
          • 더보기
            #
            cat services/catalog/kubernetes/catalog.yaml
            kubectl apply -f services/catalog/kubernetes/catalog.yaml -n istioinaction
            
            cat services/webapp/kubernetes/webapp.yaml 
            kubectl apply -f services/webapp/kubernetes/webapp.yaml -n istioinaction
            
            #
            kubectl get pod -n istioinaction
            NAME                     READY   STATUS    RESTARTS   AGE
            catalog-6cf4b97d-jx8xw   2/2     Running   0          29s
            webapp-7685bcb84-zlxmv   2/2     Running   0          29s
            
            # catalog 디플로이먼트에서 파드 관련 spec
            kubectl get deploy -n istioinaction catalog -o jsonpath="{.spec.template.spec}" | jq
            
            # catalog 파드 관련 spec : 위 디플로이먼트와 파드 spec 을 비교해보자
            kubectl get pod -n istioinaction -l app=catalog -o jsonpath="{.items[0].spec}" | jq
            
            
            # 접속 테스트용 netshoot 파드 생성
            cat <<EOF | kubectl apply -f -
            apiVersion: v1
            kind: Pod
            metadata:
              name: netshoot
            spec:
              containers:
              - name: netshoot
                image: nicolaka/netshoot
                command: ["tail"]
                args: ["-f", "/dev/null"]
              terminationGracePeriodSeconds: 0
            EOF
            
            # catalog 접속 확인
            kubectl exec -it netshoot -- curl -s http://catalog.istioinaction/items/1 | jq
            {
              "id": 1,
              "color": "amber",
              "department": "Eyewear",
              "name": "Elinor Glasses",
              "price": "282.00"
            }
            
            # webapp 접속 확인 : webapp 서비스는 다른 서비스에서 데이터를 집계해 브라우저에 시각적으로 표시한다. 
            ## 즉 webapp은 다른 백엔드 서비스의 파사드 facade 역할을 한다.
            kubectl exec -it netshoot -- curl -s http://webapp.istioinaction/api/catalog/items/1 | jq
            {
              "id": 1,
              "color": "amber",
              "department": "Eyewear",
              "name": "Elinor Glasses",
              "price": "282.00"
            }

          • 확인
          • webapp 서비스 는 다른 서비스에서 데이터를 집계해 브라우저에 시각적으로 표시
        • 복원력, 관찰가능성, 트래픽 제어
          • 더보기
            # istioctl proxy-status : 단축어 ps
            docker exec -it myk8s-control-plane istioctl proxy-status
            docker exec -it myk8s-control-plane istioctl ps
            
            #
            cat ch2/ingress-gateway.yaml
            cat <<EOF | kubectl -n istioinaction apply -f -
            apiVersion: networking.istio.io/v1alpha3
            kind: Gateway
            metadata:
              name: outfitters-gateway
              namespace: istioinaction
            spec:
              selector:
                istio: ingressgateway # use istio default controller
              servers:
              - port:
                  number: 80
                  name: http
                  protocol: HTTP
                hosts:
                - "*"
            ---
            apiVersion: networking.istio.io/v1alpha3
            kind: VirtualService
            metadata:
              name: webapp-virtualservice
              namespace: istioinaction
            spec:
              hosts:
              - "*"
              gateways:
              - outfitters-gateway
              http:
              - route:
                - destination:
                    host: webapp
                    port:
                      number: 80
            EOF
            
            #
            kubectl get gw,vs -n istioinaction
            NAME                                             AGE
            gateway.networking.istio.io/outfitters-gateway   126m
            
            NAME                                                       GATEWAYS                 HOSTS   AGE
            virtualservice.networking.istio.io/webapp-virtualservice   ["outfitters-gateway"]   ["*"]   126m
            
            
            # istioctl proxy-status : 단축어 ps
            docker exec -it myk8s-control-plane istioctl proxy-status
            NAME                                                  CLUSTER        CDS        LDS        EDS        RDS        ECDS         ISTIOD                      VERSION
            catalog-6cf4b97d-nccfj.istioinaction                  Kubernetes     SYNCED     SYNCED     SYNCED     SYNCED     NOT SENT     istiod-7df6ffc78d-bj7h7     1.17.8
            istio-ingressgateway-996bc6bb6-mz544.istio-system     Kubernetes     SYNCED     SYNCED     SYNCED     SYNCED     NOT SENT     istiod-7df6ffc78d-bj7h7     1.17.8
            webapp-7685bcb84-c55ck.istioinaction                  Kubernetes     SYNCED     SYNCED     SYNCED     SYNCED     NOT SENT     istiod-7df6ffc78d-bj7h7     1.17.8
            
            ISTIOIGW=istio-ingressgateway-996bc6bb6-647tx.istio-system
            WEBAPP=webapp-7685bcb84-nfntj.istioinaction
            
            # istioctl proxy-config : 단축어 pc
            docker exec -it myk8s-control-plane istioctl proxy-config all $ISTIOIGW
            docker exec -it myk8s-control-plane istioctl proxy-config all $WEBAPP
            
            docker exec -it myk8s-control-plane istioctl proxy-config listener $ISTIOIGW
            docker exec -it myk8s-control-plane istioctl proxy-config route $ISTIOIGW
            docker exec -it myk8s-control-plane istioctl proxy-config cluster $ISTIOIGW
            docker exec -it myk8s-control-plane istioctl proxy-config endpoint $ISTIOIGW
            docker exec -it myk8s-control-plane istioctl proxy-config log $ISTIOIGW
            
            docker exec -it myk8s-control-plane istioctl proxy-config listener $WEBAPP
            docker exec -it myk8s-control-plane istioctl proxy-config route $WEBAPP
            docker exec -it myk8s-control-plane istioctl proxy-config cluster $WEBAPP
            docker exec -it myk8s-control-plane istioctl proxy-config endpoint $WEBAPP
            docker exec -it myk8s-control-plane istioctl proxy-config log $WEBAPP
            
            # envoy 가 사용하고 있는 인증서 정보 확인
            docker exec -it myk8s-control-plane istioctl proxy-config secret $ISTIOIGW
            docker exec -it myk8s-control-plane istioctl proxy-config secret $WEBAPP
            
            
            #
            docker exec -it myk8s-control-plane istioctl proxy-config routes deploy/istio-ingressgateway.istio-system
            NAME          DOMAINS     MATCH                  VIRTUAL SERVICE
            http.8080     *           /*                     webapp-virtualservice.istioinaction
                          *           /stats/prometheus*
                          *           /healthz/ready*
            
            
            # istio-ingressgateway 서비스 NodePort 변경 및 nodeport 30000로 지정 변경
            kubectl get svc,ep -n istio-system istio-ingressgateway
            kubectl patch svc -n istio-system istio-ingressgateway -p '{"spec": {"type": "NodePort", "ports": [{"port": 80, "targetPort": 8080, "nodePort": 30000}]}}'
            kubectl get svc -n istio-system istio-ingressgateway
            
            # istio-ingressgateway 서비스 externalTrafficPolicy 설정 : ClientIP 수집 확인
            kubectl patch svc -n istio-system istio-ingressgateway -p '{"spec":{"externalTrafficPolicy": "Local"}}'
            kubectl describe svc -n istio-system istio-ingressgateway
            
            #
            kubectl stern -l app=webapp -n istioinaction
            kubectl stern -l app=catalog -n istioinaction
            
            #
            curl -s http://127.0.0.1:30000/api/catalog | jq
            curl -s http://127.0.0.1:30000/api/catalog/items/1 | jq
            curl -s http://127.0.0.1:30000/api/catalog -I | head -n 1
            
            # webapp 반복 호출
            while true; do curl -s http://127.0.0.1:30000/api/catalog/items/1 ; sleep 1; echo; done
            while true; do curl -s http://127.0.0.1:30000/api/catalog -I | head -n 1 ; date "+%Y-%m-%d %H:%M:%S" ; sleep 1; echo; done
            while true; do curl -s http://127.0.0.1:30000/api/catalog -I | head -n 1 ; date "+%Y-%m-%d %H:%M:%S" ; sleep 0.5; echo; done
          • 확인
        • Observability (관찰가능성)
          • 더보기
            # NodePort 변경 및 nodeport 30001~30003으로 변경 : prometheus(30001), grafana(30002), kiali(30003), tracing(30004)
            kubectl patch svc -n istio-system prometheus -p '{"spec": {"type": "NodePort", "ports": [{"port": 9090, "targetPort": 9090, "nodePort": 30001}]}}'
            kubectl patch svc -n istio-system grafana -p '{"spec": {"type": "NodePort", "ports": [{"port": 3000, "targetPort": 3000, "nodePort": 30002}]}}'
            kubectl patch svc -n istio-system kiali -p '{"spec": {"type": "NodePort", "ports": [{"port": 20001, "targetPort": 20001, "nodePort": 30003}]}}'
            kubectl patch svc -n istio-system tracing -p '{"spec": {"type": "NodePort", "ports": [{"port": 80, "targetPort": 16686, "nodePort": 30004}]}}'
            
            # Prometheus 접속 : envoy, istio 메트릭 확인
            open http://127.0.0.1:30001
            
            # Grafana 접속
            open http://127.0.0.1:30002
            
            # Kiali 접속 1 : NodePort
            open http://127.0.0.1:30003
            
            # (옵션) Kiali 접속 2 : Port forward
            kubectl port-forward deployment/kiali -n istio-system 20001:20001 &
            open http://127.0.0.1:20001
            
            # tracing 접속 : 예거 트레이싱 대시보드
            open http://127.0.0.1:30004
          • 확인
            • Prometheus 접속 : envoy, istio 메트릭 확인
              Grafana 접속
              kiali 접속

              jagger 접속 (tracing)



          • catalog에 의도적으로 500에러를 재현하고 retry로 복원력 높이기
            • bin/chaos.sh {에러코드} {빈도} - chaos.sh 500 50 (500에러를 50% 빈도로 재현)
              • 더보기
                #
                docker exec -it myk8s-control-plane bash
                ----------------------------------------
                # istioinaction 로 네임스페이스 변경
                cat /etc/kubernetes/admin.conf
                kubectl config set-context $(kubectl config current-context) --namespace=istioinaction
                cat /etc/kubernetes/admin.conf
                
                cd /istiobook/bin/ 
                ./chaos.sh 500 100 # 모니터링 : kiali, grafana, tracing
                
                ./chaos.sh 500 50 # 모니터링 : kiali, grafana, tracing
                
                
                kubectl config set-context $(kubectl config current-context) --namespace=default
                cat /etc/kubernetes/admin.conf
                ----------------------------------------
            • 확인

            •