# 실습

### Introduction

1. Envoy Gateway 설치

   ```
   helm install eg oci://docker.io/envoyproxy/gateway-helm \
   --version v1.0.1 \
   --namespace envoy-gateway-system \
   --create-namespace
   ```
2. 생성된 객체 확인&#x20;

   ```
   kubectl get all -n envoy-gateway-system
   ```
3. Envoy Gateway 설정 파일 확인&#x20;

   ```
   kubectl get cm -n envoy-gateway-system envoy-gateway-config -o yaml
   ```
4. GatewayClass 목록 확인&#x20;

   ```
   kubectl get gatewayclass -A
   ```
5. Envoy Proxy 사용자 지정 설정 추가

   ```
   cat <<EOF | kubectl apply -f -
   apiVersion: gateway.envoyproxy.io/v1alpha1
   kind: EnvoyProxy
   metadata:
     name: custom-proxy-config
     namespace: envoy-gateway-system
   spec:
     provider:
       type: Kubernetes
       kubernetes:
         envoyService:
           annotations:
             service.beta.kubernetes.io/aws-load-balancer-type: external
             service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
             service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
   EOF
   ```
6. GatewayClass 생성&#x20;

   ```
   cat <<EOF | kubectl apply -f -
   apiVersion: gateway.networking.k8s.io/v1
   kind: GatewayClass
   metadata:
     name: eg
   spec:
     controllerName: gateway.envoyproxy.io/gatewayclass-controller
     parametersRef:
       group: gateway.envoyproxy.io
       kind: EnvoyProxy
       namespace: envoy-gateway-system
       name: custom-proxy-config
   EOF
   ```
7. Gateway 생성&#x20;

   ```
   cat <<EOF | kubectl apply -f -
   apiVersion: gateway.networking.k8s.io/v1
   kind: Gateway
   metadata:
     name: eg
   spec:
     gatewayClassName: eg
     listeners:
     - name: http
       protocol: HTTP
       port: 80
   EOF
   ```
8. 생성된 Gateway 확인&#x20;

   ```
   kubectl get gateway eg
   ```
9. Envoy Gateway가 설치된 네임스페이스에 추가로 생성된 객체 확인&#x20;

   ```
   kubectl get all -n envoy-gateway-system
   ```
10. Gateway의 주소로 접근 시도

    ```
    curl $(kubectl get gateway eg -o=jsonpath='{.status.addresses[0].value}') -v
    ```
11. 데모 애플리케이션 배포&#x20;

    ```
    {
      kubectl create deployment nginx --image=nginx --port=80
      kubectl expose deploy nginx
    }
    ```
12. HTTPRoute 생성&#x20;

    ```
    cat <<EOF | kubectl apply -f -
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: nginx
    spec:
      parentRefs:
      - name: eg
      rules:
      - backendRefs:
        - name: nginx
          port: 80
    EOF
    ```
13. 생성된 HTTPRoute의 상세 내용 확인&#x20;

    ```
    kubectl describe httproute nginx
    ```
14. Gateway 엔드포인트 호출&#x20;

    ```
    curl $(kubectl get gateway eg -o=jsonpath='{.status.addresses[0].value}')
    ```
15. HTTPRoute 수정

    ```
    cat <<EOF | kubectl apply -f -
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: nginx
    spec:
      parentRefs:
      - name: eg
      hostnames:
      - nginx.example.com
      rules:
      - backendRefs:
        - name: nginx
          port: 80
    EOF
    ```
16. Gateway 엔드포인트 호출&#x20;

    ```
    curl $(kubectl get gateway eg -o=jsonpath='{.status.addresses[0].value}') -v
    ```
17. HTTPRoute에 명시한 Host 이름을 HTTP 헤더값에 추가하고 Gateway 엔드포인트 호출

    ```
    curl -H "Host: nginx.example.com" \
    $(kubectl get gateway eg -o=jsonpath='{.status.addresses[0].value}')
    ```
18. 리소스 삭제&#x20;

    ```
    {
      kubectl delete httproute nginx
      kubectl delete svc nginx
      kubectl delete deploy nginx
      kubectl delete gateway eg
      kubectl delete gatewayclass eg
      kubectl delete envoyproxy custom-proxy-config -n envoy-gateway-system
    }
    ```
19. Envoy Gateway가 설치된 네임스페이스의 객체 목록 확인&#x20;

    ```
    kubectl get all -n envoy-gateway-system
    ```

```
aaa
```
