실습

Prerequisite

  1. AWS Load Balancer Controller에 명시된 내용을 참고해서 AWS Load Balancer Controller 설치

Installation

Ingress Gateway

TLS

  1. Istio 설치

    cat <<'EOF' | istioctl install -y -f -
    apiVersion: install.istio.io/v1alpha1
    kind: IstioOperator
    spec:
      components:
        ingressGateways:
          - name: istio-ingressgateway
            enabled: true
            k8s:
              serviceAnnotations:
                service.beta.kubernetes.io/aws-load-balancer-type: external
                service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance
                service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
                service.beta.kubernetes.io/aws-load-balancer-attributes: load_balancing.cross_zone.enabled=true
              service:
                externalTrafficPolicy: Cluster
                loadBalancerSourceRanges:
                  - 0.0.0.0/0
    EOF
  2. CA 인증서 생성

    openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 \
    -subj '/CN=example.com' -keyout ca-key.pem -out ca-cert.pem
  3. example.com 도메인에 인증서 서명 요청 및 키 생성

    openssl req -newkey rsa:2048 -nodes \
    -subj "/CN=*.example.com" -keyout example.com.key -out example.com.csr
  4. 인증서 서명

    openssl x509 -req -sha256 -days 365 -CA ca-cert.pem -CAkey ca-key.pem \
    -set_serial 0 -in example.com.csr -out example.com.crt
  5. Secret 생성

    kubectl create -n istio-system secret tls example-com \
    --key=example.com.key --cert=example.com.crt
  6. Gateway 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: istio-gateway
    spec:
      selector:
        istio: ingressgateway 
      servers:
      - port:
          number: 443
          name: https
          protocol: HTTPS
        tls:
          mode: SIMPLE
          credentialName: example-com
        hosts:
        - "*"
    EOF
  7. VirtualService 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: nginx
    spec:
      hosts:
      - "nginx.example.com"
      gateways:
      - istio-gateway
      http:
      - match:
        - uri:
            prefix: /
        route:
        - destination:
            host: nginx
            port:
              number: 80
    EOF
  8. 데모 애플리케이션 배포

    cat <<EOF | kubectl apply -f -
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: nginx
      name: nginx
    spec:
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
            ports:
            - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      ports:
      - port: 80
      selector:
        app: nginx
    EOF
  9. 데모 애플리케이션 호출 - HTTPS

    curl -H "Host: nginx.example.com" --cacert ca-cert.pem --insecure -v \
    https://$(kubectl -n istio-system get svc istio-ingressgateway -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')
  10. Gateway에 HTTPS Redirect 설정

    cat <<EOF | kubectl apply -f -
    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: istio-gateway
    spec:
      selector:
        istio: ingressgateway 
      servers:
      - port:
          number: 80
          name: http
          protocol: HTTP
        tls:
          httpsRedirect: true
        hosts:
        - "*"
      - port:
          number: 443
          name: https
          protocol: HTTPS
        tls:
          mode: SIMPLE
          credentialName: example-com
        hosts:
        - "*"
    EOF
  11. 데모 애플리케이션 호출 - HTTP

    curl -H "Host: nginx.example.com" --cacert ca-cert.pem --insecure -v -L \
    http://$(kubectl -n istio-system get svc istio-ingressgateway -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')
  12. Gateway에 설정한 HTTPS Redirect 삭제

    cat <<EOF | kubectl apply -f -
    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: istio-gateway
    spec:
      selector:
        istio: ingressgateway 
      servers:
      - port:
          number: 80
          name: http
          protocol: HTTP
        hosts:
        - "*"
      - port:
          number: 443
          name: https
          protocol: HTTPS
        tls:
          mode: SIMPLE
          credentialName: example-com
        hosts:
        - "*"
    EOF
  13. VirtualService HTTPS Redirect 설정

    cat <<EOF | kubectl apply -f -
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: nginx
    spec:
      hosts:
      - "nginx.example.com"
      gateways:
      - istio-gateway
      http:
      - match:
        - scheme:
            exact: http
        redirect:
          scheme: https
          redirectCode: 308
      - match:
        - uri:
            prefix: /
        route:
        - destination:
            host: nginx
            port:
              number: 80
    EOF
  14. 데모 애플리케이션 호출 - HTTPS

    curl -H "Host: nginx.example.com" --cacert ca-cert.pem --insecure -v \
    https://$(kubectl -n istio-system get svc istio-ingressgateway -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')
  15. 데모 애플리케이션 호출 - HTTP

    curl -H "Host: nginx.example.com" --cacert ca-cert.pem --insecure -v -L \
    http://$(kubectl -n istio-system get svc istio-ingressgateway -o=jsonpath='{.status.loadBalancer.ingress[0].hostname}')
  16. 리소스 삭제

    kubectl delete deploy nginx
    kubectl delete svc nginx
    kubectl delete virtualservices.networking.istio.io nginx 
    kubectl delete gateways.networking.istio.io istio-gateway
    kubectl delete -n istio-system secret example-com
    istioctl x uninstall -y --purge

TLS with NLB

  1. AWS Certificate Manager를 통해서 SSL 인증서 발급

  2. 사용할 ACM 인증서의 ARN을 환경변수로 지정

    e.g.

  3. Istio 설치

  4. 사용할 Top 레벨 도메인주소를 환경변수로 지정

    e.g.

  5. Gateway 생성

  6. VirtualService 생성

  7. 데모 애플리케이션 배포

  8. 아래의 명령어를 실행해서 나온 결과값과 같은 DNS 레코드 생성

  9. 데모 애플리케이션 호출 - HTTPS

  10. 데모 애플리케이션 호출 - HTTP

  11. Gateway에 HTTPS Redirect 설정

  12. 데모 애플리케이션 호출 - HTTPS

  13. 데모 애플리케이션 호출 - HTTP

  14. NLB와 Istio Ingress Gateway는 HTTP 프로토콜로 통신하므로 모든 요청이 HTTPS로 전환됨

  15. Gateway에 설정한 HTTPS Redirect 삭제

  16. 데모 애플리케이션 호출 - HTTPS

  17. 데모 애플리케이션 호출 - HTTP

  18. VirtualService에 HTTPS Redirect 설정

  19. 데모 애플리케이션 호출 - HTTPS

  20. 데모 애플리케이션 호출 - HTTP

  21. VirtualService 설정한 HTTPS Redirect 삭제

  22. 데모 애플리케이션 호출 - HTTPS

  23. 데모 애플리케이션 호출 - HTTP

  24. Istio 설정변경 - NLB(HTTP) -> Istio Ingress Gateway(HTTP), NLB(HTTPS) -> Istio Ingress Gateway(HTTPS)로 라우팅 되도록 구성

  25. 데모 애플리케이션 호출 - HTTPS

  26. 데모 애플리케이션 호출 - HTTP

  27. Gateway에 443 포트 리스너 추가

  28. 데모 애플리케이션 호출 - HTTPS

  29. Gateway에 HTTPS Redirect 설정

  30. 데모 애플리케이션 호출 - HTTPS

  31. 데모 애플리케이션 호출 - HTTP

  32. 데모 애플리케이션 배포 - https://github.com/youngwjung/flask-echo

  33. VirtualService 생성

  34. 아래의 명령어를 실행해서 나온 결과값과 같은 DNS 레코드 생성

  35. 데모 애플리케이션 호출 - HTTPS

  36. 데모 애플리케이션 호출 - HTTP

  37. Gateway에 설정한 HTTPS Redirect 삭제

  38. 데모 애플리케이션 호출 - HTTP

  39. VirtualService에 HTTPS Redirect 설정

  40. 데모 애플리케이션 호출 - HTTPS

  41. 데모 애플리케이션 호출 - HTTP

  42. 리소스 삭제

Authorization

  1. Istio 설치

  2. Gateway 생성

  3. 데모 애플리케이션 배포

  4. 데모 애플리케이션 호출

  5. 내 컴퓨터(혹은 현재 접속된 Cloud9 인스턴스) IP 주소 확인

  6. 내 컴퓨터에서 Ingress Gateway로 접근 차단

  7. 데모 애플리케이션 호출

  8. Ingress Gateway 로그 확인

  9. Envoy 로그 활성화

  10. Ingress Gateway 재생성

  11. 데모 애플리케이션 호출

  12. Ingress Gateway 로그 확인

  13. NLB 설정 변경

  14. 데모 애플리케이션 호출

  15. Ingress Gateway 로그 확인

  16. NLB 설정 변경

  17. Envoy Filter 생성 - Proxy Protocol

  18. Envoy Filter 생성 - X-Forwarded-For 헤더

  19. 데모 애플리케이션 호출

  20. Ingress Gateway 로그 확인

  21. 데모 애플리케이션 호출

  22. Ingress Gateway 로그 확인

  23. 리소스 삭제

Service Entry

Introduction

  1. Istio 설치

  2. default 네임스페이스에 생성되는 Pod에 프록시 주입 설정

  3. Pod 생성

  4. Pod가 생성되고 프록시 컨테이너가 추가되었는지 확인

  5. 생성한 Pod에서 httpbin.org 접근 시도

  6. Pod에서 httpbin.org 접근 시도

  7. Pod에서 httpbin.org 접근 시도

  8. 리소스 삭제

Deep Dive

  1. Istio 설치

  2. default 네임스페이스에 생성되는 Pod에 프록시 주입 설정

  3. Pod 생성

  4. Pod가 생성되고 프록시 컨테이너가 추가되었는지 확인

  5. Istio Sidecar Proxy가 사용하는 포트 확인 - https://istio.io/latest/docs/ops/deployment/requirements/#ports-used-by-istio

  6. Sidecar Proxy의 아웃바운드 설정 확인 - https://faun.pub/understanding-how-envoy-sidecar-intercept-and-route-traffic-in-istio-service-mesh-20fea2a78833

    요약: 목적지 포트가 15001일 경우에는 BlackHoleCluster로 아닐 경우에는 PassthroughCluster로

  7. Sidecar Proxy의 클러스터 설정 확인

  8. PassthroughCluster의 상세 설정 확인 - InboundPassthroughClusterIpv4 및 PassthroughCluster에 대한 정보가 보여지므로 name 값을 확인해서 PassthroughCluster에 대한 정보만 확인

  9. BlackHoleCluster의 상세 설정 확인

  10. 생성한 Pod에서 httpbin.org 접근 시도

  11. Istio 아웃바운드 트래픽 정책 변경

  12. Pod에서 httpbin.org 접근 시도

  13. Sidecar Proxy의 리스너 설정 확인

  14. Sidecar Proxy의 아웃바운드 설정 확인

    요약: 목적지 포트가 15001일 경우에는 BlackHoleCluster로 아닐 경우에도 BlackHoleCluster로

  15. ServiceEntry 생성

  16. Pod에서 httpbin.org 접근 시도

  17. Sidecar Proxy의 Route 설정 확인

  18. Sidecar Proxy의 Route 설정 확인 - 80/httpbin.org

    요약: 포트 80으로 나갈때 호스트가 httpbin.org을 경우 httpbin.org 클러스터로 아닐 경우 502 반환

  19. Pod에서 google.com 접근 시도

  20. Sidecar Proxy의 클러스터 설정 확인

  21. httpbin.org 의 상세 설정 확인

  22. 리소스 삭제

External HTTPS Proxy

  1. Istio 설치

  2. default 네임스페이스에 생성되는 Pod에 프록시 주입 설정

  3. HTTPS Proxy를 배포할 Namespace 생성

  4. Squid proxy 설정파일 생성

  5. Squid proxy 생성

  6. Squid proxy 생성 확인

  7. Sidecar Proxy가 없는 Pod 생성

  8. Squid proxy를 통해서 외부 HTTPS 서비스 호출

  9. Squid proxy를 통해서 외부 HTTP 서비스 호출

  10. Squid proxy 로그 확인

  11. Sidecar Proxy를 포함하는 Pod 생성

  12. Squid proxy를 통해서 외부 HTTPS 서비스 호출

  13. Squid proxy를 통해서 외부 HTTP 서비스 호출

  14. Squid proxy 로그 확인

  15. Sidecar Proxy 로그 확인

  16. Istio 아웃바운드 트래픽 정책 변경

  17. Squid proxy를 통해서 외부 HTTPS 서비스 호출

  18. Squid proxy를 통해서 외부 HTTP 서비스 호출

  19. Squid proxy 로그 확인

  20. Sidecar Proxy 로그 확인

  21. ServiceEntry 생성

  22. Squid proxy를 통해서 외부 HTTPS 서비스 호출

  23. Squid proxy를 통해서 외부 HTTP 서비스 호출

  24. Squid proxy 로그 확인

  25. Sidecar Proxy 로그 확인

  26. ServiceEntry 변경 - TCP 프로토콜 사용

  27. Squid proxy를 통해서 외부 HTTPS 서비스 호출

  28. Squid proxy를 통해서 외부 HTTP 서비스 호출

  29. Squid proxy 로그 확인

  30. Sidecar Proxy 로그 확인

  31. 리소스 삭제

Last updated