6주차 - Gateway API
0. 목적성
Gateway API의 주요 기능을 알아보고 Gateway API 가 생겨난 이유와 GATEWAY API 의 구성요소를 알아봅니다.
Gloo Gateway로 KIND 내에서 실제 통신흐름을 알아봅니다.
마지막으로, Ingress vs Gateway API vs Service Mesh 각각의 차이점과 비교 그리고 특장점 및 향후 어떻게 될지 정리해봅니다.
1. Gateway API
Gateway API 는 Ingress에 비해 명확한 상세와 추가적으로 필요한 명세들을 명확히한 기능입니다.
HTTP에 국한되어있던 INGRESS와 달리 TCP, UDP, TLS 와같은 프로토콜도 지원합니다.
또, TLS 구성 과 세부적인 액세스 제어에 대해 기본적으로 지원합니다.
역할 지향적 설계로 클러스터 운영자, 애플리케이션 개발자, 보안 팀 간의 관심사를 명확하게 분리합니다.
1.1 Gateway API 소개

서비스 메시(istio)에서 제공하는 기능 중 일부기능들과 운영 관리에 필요한 기능들을 추가했습니다.
추가 기능: 헤더 기반 라우팅, 헤더 변조, 트래픽 미러링(쉽게 트래픽 복제), 역할 기반, 로드밸런싱 로직
gatewayClass는 인프라레벨의 설정들을 명시하고 어떤 controller를 사용할지 명시한다.
kind: GatewayClass
metadata:
name: internet // 인터넷망을 통한 게이트웨이 클래스 선언
spec:
controllerName: "istio/gateway-controller"
---
kind: GatewayClass
metadata:
name: private // 내부망을 통한 게이트웨이 클래스 선언
spec:
controllerName: "istio/gateway-controller"
gateway : gatewayClass 에 의해 Gateway를 프로비져닝합니다. (src: https://istio.io/latest/docs/reference/config/networking/gateway/)
Gateway
설정은 다음과 같습니다.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: example-gateway
spec:
gatewayClassName: private // 위에 설정한 class의 이름
listeners: // hostname, port, protocol, termination, tls 설정
- name: http
protocol: HTTP
port: 80
1.2 Gateway API 구성요소

의존성은 다음 그래프에서 처럼 그려집니다.
HTTPRoute이 HTTP 에 대한 규칙들로 GATEWAY Listener에 대한 설정을 할 수 있습니다.
Gateway 는 실행되고있는 instance입니다.
gateway class는 인프라설정값이 들어간 interface로 생각하면 됩니다.
1.3 Gateway API Role Oriented API 란?

과거의 routing에 대해서 지속적으로 devops 팀에 요청해야되는 부분들을 HTTP ROUTE 이라는 리소스를 DEVELOPER가 관리하게 되면서, PATH 라우팅 정책을 스스로 관리할 수 있습니다.
1.4 [실습] Gloo Gateway
kind cluster 설치
cat <<EOT> kind-1node.yaml
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
EOT
# Install KinD Cluster
kind create cluster --image kindest/node:v1.30.0 --config kind-1node.yaml --name myk8s
# 노드에 기본 툴 설치
docker exec -it myk8s-control-plane sh -c 'apt update && apt install tree psmisc lsof wget bsdmainutils bridge-utils net-tools dnsutils tcpdump ngrep iputils-ping git vim -y'

Gateway API CRDs 설치
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/standard-install.yaml

Glooctl 설치
**Install Glooctl Utility** : GLOOCTL is a command-line utility that allows users to view, manage, and debug Gloo Gateway deployments - [Link](https://docs.solo.io/gloo-edge/latest/installation/glooctl_setup/)
```bash
# [신규 터미널] 아래 bash 진입 후 glooctl 툴 사용
**docker exec -it myk8s-control-plane bash**
----------------------------------------
# Install Glooctl Utility
## glooctl install gateway # install gloo's function gateway functionality into the 'gloo-system' namespace
## glooctl install ingress # install very basic Kubernetes Ingress support with Gloo into namespace gloo-system
## glooctl install knative # install Knative serving with Gloo configured as the default cluster ingress
## curl -sL https://run.solo.io/gloo/install | sh
**curl -sL https://run.solo.io/gloo/install | GLOO_VERSION=v1.17.7 sh**
export PATH=$HOME/.gloo/bin:$PATH
# 버전 확인
**glooctl version**
----------------------------------------
```

Gloo Gateway 설치
watch -d kubectl get pod,svc,endpointslices,ep -n gloo-system
# Install Gloo Gateway
## --set kubeGateway.enabled=true: Kubernetes Gateway 기능을 활성화합니다.
## --set gloo.disableLeaderElection=true: Gloo의 리더 선출 기능을 비활성화합니다. (단일 인스턴스에서 Gloo를 실행 시 유용)
## --set discovery.enabled=false: 서비스 디스커버리 기능을 비활성화합니다.
helm repo add gloo https://storage.googleapis.com/solo-public-helm
helm repo update
helm install -n gloo-system gloo-gateway gloo/gloo \
--create-namespace \
--version 1.17.7 \
--set kubeGateway.enabled=true \
--set gloo.disableLeaderElection=true \
--set discovery.enabled=false
# Confirm that the Gloo control plane has successfully been deployed using this command
kubectl rollout status deployment/gloo -n gloo-system


# Install Httpbin Application
kubectl apply -f https://raw.githubusercontent.com/solo-io/solo-blog/main/gateway-api-tutorial/01-httpbin-svc.yaml
# 설치 확인
kubectl get deploy,pod,svc,endpointslices,sa -n httpbin
kubectl rollout status deploy/httpbin -n httpbin
# (옵션) NodePort 설정
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
labels:
app: httpbin
service: httpbin
name: httpbin
namespace: httpbin
spec:
type: NodePort
ports:
- name: http
port: 8000
targetPort: 80
nodePort: 30000
selector:
app: httpbin
EOF



// gateway 를 실제로 http listner에 Proxy를 external Access에 노출합니다.

// Configure Simple Routing with an HTTPRoute
kubectl apply -f https://raw.githubusercontent.com/solo-io/gloo-gateway-use-cases/main/gateway-api-tutorial/03-httpbin-route.yaml
kubectl get httproute -n httpbin

Last updated