0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PR: デジタル創作サークルUniProject
UniProject公式HP

さて、どうもこんにちは。
いつも通り眠い目を擦りながらメンテナンスに追われる毎日でございます。

Gateway APIについてはこちらを。

Envoy Gatewayの何がうれぴいのかについては後日記事を書きます。

ひとまず公式サイトのリンクも貼っておきます。

前提条件

下記環境で行っています。

yuito-it@control-1:~$ kubectl version
Client Version: v1.37.1
Kustomize Version: v5.8.1
Server Version: v1.37.0
yuito-it@control-1:~$ uname -a
Linux control-1 7.1.0-070100-generic #202606141628 SMP PREEMPT_DYNAMIC Sun Jun 14 17:22:46 UTC 2026 x86_64 GNU/Linux
yuito-it@control-1:~$ helm version
version.BuildInfo{Version:"v4.3.2", GitCommit:"8346aaa55e7161f7c547212d0a87f01367976727", GitTreeState:"clean", GoVersion:"go1.27.4", KubeClientVersion:"v1.37"}

ServiceType: LoadBalancerをサポートする必要があるので、MetalLBなんかをインスコしておくと良いかと思います。
ちなみに私はCilium信者なのでCiliumを使っています。
Cilium + IPv6でKubernetesのコンテナを楽々ポート解放したい方は下記記事も参考にすると良いでしょう。

やったこと

TraefikからEnvoy Gatewayに変えました。

  1. Envoy Gatewayを入れる
  2. cert-managerを入れる
  3. Gateway Classをつくる
  4. Custom Proxyをつくる
  5. Gatewayをつくる
  6. HTTP Routeを量産する

また、この記事では、下記のInstallページのhelmと同じ手順を踏んでいきます。
他の方法がいい人はおそらくこの記事を読んでいないでしょうが、気になる人は見てみてください。

1. Envoy Gatewayをインスコする

まずはEnvoy Gateway本体をインスコしないと始まりません。
Envoy GatewayはTraefikのようにhelmなどでインスコできます。

## インスコ
helm install eg oci://docker.io/envoyproxy/gateway-helm --version v1.10.0 -n envoy-gateway-system --create-namespace
## デプロイ完了まで待つ
kubectl wait --timeout=5m -n envoy-gateway-system deployment/envoy-gateway --for=condition=Available

2. cert-managerを入れてセットアップする

さて、Traefikを使っている方はもしかしたら馴染みがないかもしれませんが、cert-managerを入れます。
これはなぜかというと、Traefikは独自のACMEの解決メソッドを持っていますが、Envoy Gatewayにはないので、別で証明書をとってくる必要があるからです。
Ingress NGINXの頃を思い出しますね。

下記ページを参考にインストールします。

が、私はhelm大好き人間なので下記ページに載っているkubectlでのインストールではなく、helmでインストールします。

curl -LO https://cert-manager.io/public-keys/cert-manager-keyring-2021-09-20-1020CF3C033D4F35BAE1C19E1226061C665DF13E.gpg

helm install \
  cert-manager oci://quay.io/jetstack/charts/cert-manager \
  --version v1.21.3 \
  --namespace cert-manager \
  --create-namespace \
  --verify \
  --keyring ./cert-manager-keyring-2021-09-20-1020CF3C033D4F35BAE1C19E1226061C665DF13E.gpg \
  --set crds.enabled=true

ここから先のセットアップは過去の自分によろしくすることにします。
Cloudflareをお使いの方は下記記事を参照してください。

大変申し訳ないのですがHTTP01で認証することがないのでそちらは各自で調べていただけますと :bow:

3. Gateway Classをつくる

ただのおまじないだと思ってもOKです。
ただただ、いちいち長ったらしいAPIの名前を書かなくていいようにGatewayClassというものを作りますよ、とでも思えば良いです。

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: envoy-gateway
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
  description: "Envoy Gateway Controller for all services"

4. IPv6を使うべくCustom Proxyをつくる (省略可)

外部向けのサービスが多い当サークルですが...IPv4いっぱい持っているお金持ちじゃないので、もちろんIPv6をフル活用していきたいと思います。
ということで、IPv6も発行してもらうべくDual Stackにしておきます。

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: dualstack-proxy-config
  namespace: infra-gateway
spec:
  ipFamily: DualStack

5. Gatewayをつくる

Gatewayをつくります。

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: uniproject-jp-gateway
  namespace: infra-gateway
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod" # ここに2でつくったClusterIssuerの名前を
spec:
  gatewayClassName: envoy-gateway
  ## 4でIPv6 DualStackにしたらコメントアウトを解除
  #infrastructure:
  #  parametersRef:
  #    group: gateway.envoyproxy.io
  #    kind: EnvoyProxy
  #    name: dualstack-proxy-config
  listeners:
    - name: https-wildcard
      protocol: HTTPS
      port: 443
      hostname: "*.uniproject.jp" # 受け入れるホスト名
      tls:
        mode: Terminate
        certificateRefs:
          - name: wildcard-uniproject-jp-tls
      allowedRoutes:
        namespaces:
          from: All # Namespaceを制限することもできる。例えば同じnamespaceのみなど
    - name: https-apex
      protocol: HTTPS
      port: 443
      hostname: "uniproject.jp" # 上のワイルドカードはapexを含まない
      tls:
        mode: Terminate
        certificateRefs:
          - name: wildcard-uniproject-jp-tls
      allowedRoutes:
        namespaces:
          from: All

これで、gatewayを取得してやるとIPが振られていることがわかります。
(私はIPv6シングルスタックなので、IPv6しか見えていません。)

yuito-it@control-1:~$ kubectl get gateway -A
NAMESPACE       NAME                    CLASS           ADDRESS                     PROGRAMMED   AGE
infra-gateway   uniproject-jp-gateway   envoy-gateway   xxxx:13:xxxx:xxxx:xxxx::xxxx   True         128d
infra-gateway   unpr-jp-gateway         envoy-gateway   xxxx:13:xxxx:xxxx:xxxx::xxxx   True         83d

6. HTTP Routeを量産する

HTTP Routeを量産します。

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: unipro-site
  namespace: unipro-site
spec:
  hostnames:
    # ホスト名
    - www.uniproject.jp
  parentRefs:
    # さっきつくったgatewayを入れる
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: uniproject-jp-gateway
      namespace: infra-gateway
  rules:
    # バックグラウンドPodの情報
    - backendRefs:
        - group: ""
          kind: Service
          name: unipro-site
          port: 80
          weight: 1
      matches:
        - path:
            type: PathPrefix
            value: /
      # これを指定すると、ロードバランシングする時に同じサーバーに割り当ててくれる
      sessionPersistence:
        cookieConfig:
          lifetimeType: Session
        sessionName: cookie
        type: Cookie

あとは、5で確認したIPをDNSに設定してアクセスできれば完璧です!

最後に

Envoy Gatewayは慣れれば便利なので、これからもこねくり回してみようと思います。
誰かのお役に立てれば幸いです。


デジタル創作サークルUniProjectでは、ProxmoxVE や Kubernetes などの運用も行なっています。
もし気になった方がいらっしゃいましたら、下記URLをご参照ください!

⭐︎ 公式 HP ↓

⭐︎ Discord ↓

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?