---
title: "APISIX Ingress ControllerでGateway APIを使用する方法 - API7.ai"
description: "本記事では、外部にサービスを公開するための仕様であるKubernetes Gateway APIと、APISIX Ingress ControllerでGateway APIを使用する方法について紹介します。"
url: "https://api7.ai/ja/blog/how-to-use-gateway-api-in-apisix-ingress-controller"
---

[Blog](https://api7.ai/ja/blog)

[Products](https://api7.ai/ja/category/products)[Technology](https://api7.ai/ja/category/technology)[Ecosystem](https://api7.ai/ja/category/ecosystem)[Case Study](https://api7.ai/ja/category/usercase)[Team & Community](https://api7.ai/ja/category/community)

Search

⌘ + K

[Blog](https://api7.ai/blog)

Products

# APISIX Ingress ControllerでGateway APIを使用する方法

Yeqi Peng

November 11, 2022

[Products](https://api7.ai/category/products)

## Kubernetes Gateway APIとは

[Gateway API](https://api7.ai/blog/a-quick-glance-at-the-kubernetes-gateway-api)は、KubernetesのネイティブなServiceやIngressに加えて、クラスタ外にサービスを公開するためのもう一つのコミュニティ主導の仕様（sig-networkによって管理されています）です。

Gateway APIは、HTTP、TCP、UDPなどの一般的なネットワークプロトコルやTLSをサポートしています。さらに、Gateway APIにはGatewayリソースが含まれており、Kubernetes APIを通じてプロキシやゲートウェイのライフサイクルを管理することが可能です。

### Gateway APIが必要な理由

Ingressと比較して、Gateway APIはIngressの機能的な上位互換であり、以下のような改善点があります：

- **ロール指向**: Gatewayは、Kubernetesのサービスネットワーキングを使用および設定する組織のロールをモデル化したAPIリソースで構成されています。
- **表現力が豊か**: Gateway APIリソースは、ヘッダーベースのマッチング、トラフィックの重み付けなどのコア機能をサポートしており、これらはIngressではカスタムアノテーションを通じてのみ実現可能でした。
- **拡張性**: Gateway APIは、APIのさまざまな層でカスタムリソースをリンクすることを可能にし、API構造内の適切な場所で細かいカスタマイズを実現します。

さらに、この仕様には、移植性、共有ゲートウェイ、クロスネームスペース参照などの機能も含まれています。

図に示すように、ロール指向の設計により、クラスタ内のネットワークインフラを異なるチーム間で共有し、クラスタ管理者によって設定されたポリシーや制約を共有することができます。これにより、インフラプロバイダー、クラスタ管理者、アプリケーション開発者などの異なるタイプのロールが、他のロールの責任範囲に気を取られることなく、自身の作業に集中できるようになります。

![api-mode.png](https://static.api7.ai/2022/10/03/633a3b34999dd.png?imageMogr2/format/webp)

異なるロールが異なるレベルのGateway APIリソースを設定し、それらのレベルが連携して動作します：

![gateway-roles.png](https://static.api7.ai/2022/11/09/636b86f7845a1.png?imageMogr2/format/webp)

### Gateway APIの現状

現在、Gateway API v0.5.0のリリースに伴い、GatewayClass、Gateway、HTTPRouteなどの重要なコアAPIが初めてBeta版となりました。

## APISIX IngressでGateway APIを使用する方法

[APISIX Ingress Controller](https://api7.ai/blog/apisix-ingress-vs-ingress-nginx)のGateway APIサポートは開発中であり、現在はAlpha段階で、HTTPRouteやTCPRouteなどのリソースをサポートしています。

### Gateway API CRDのインストール

Gateway APIを使用するには、まずGateway APIのCRDをインストールする必要があります。これは、APISIX Ingress Controllerリポジトリのコピーまたは公式リポジトリ[kubernetes-sigs/gateway-api](https://github.com/kubernetes-sigs/gateway-api/tree/main/config/crd/experimental)からインストールできます。ここでは、APISIX Ingress ControllerリポジトリのCRDのコピーを使用する例を示します。

以下のコマンドを実行して、Gateway APIのCRDをインストールします。

```
git pull git@github.com:apache/apisix-ingress-controller.git
cd apisix-ingress-controller

kubectl apply -f ./samples/deploy/gateway-api/
```

### APISIX Ingress Controllerのインストール

APISIX Ingress Controllerでは、デフォルトでGateway APIサポートが有効になっていないため、`-enable-gateway-api=true`パラメータを使用して有効にすることができます。

Helmを使用してインストールする場合、valuesを設定することで有効にできます。

以下のコマンドを使用して、APISIXとAPISIX Ingress Controllerをインストールします。

```
helm repo add apisix https://charts.apiseven.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
kubectl create ns apisix-ingress

helm install apisix apisix/apisix --namespace apisix-ingress \
--set gateway.type=NodePort \
--set ingress-controller.enabled=true \
--set ingress-controller.config.apisix.serviceNamespace=apisix-ingress \
--set ingress-controller.config.kubernetes.enableGatewayAPI=true
```

`-set ingress-controller.config.kubernetes.enableGatewayAPI=true`パラメータに注意してください。これはGateway APIサポートを有効にするために使用されます。

これらのコマンドは、`apisix-ingress`ネームスペースの下にAPISIX、etcd、APISIX Ingress Controllerを含む完全なテスト環境を作成します。

### テストロードのデプロイ

`kennethreitz/httpbin`イメージをテストロードとして使用します。

以下のコマンドを使用して、これらのロードをデフォルトのネームスペースにデプロイします。

```
kubectl run httpbin --image kennethreitz/httpbin --port 80
kubectl expose pod httpbin --port 80
```

### HTTPRouteの設定

現在、APISIX Ingress ControllerはGateway APIリソースの`v1alpha2`バージョンをサポートしています。

テストのために、以下のHTTPRoute設定を使用し、`httproute.yaml`ファイルに保存します：

```
# httproute.yaml
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
name: basic-http-route
spec:
hostnames:
- local.httpbin.org
rules:
- backendRefs:
    - name: httpbin
    port: 80
    matches:
    - path:
        type: PathPrefix
        value: /
```

以下のコマンドを使用して、このHTTPRoute設定をデプロイします：

```
kubectl apply -f ./httproute.yaml
```

### 検証

APISIX Pod内で直接以下のコマンドを実行して検証できます：

```
kubectl -n apisix-ingress exec -it $(kubectl -n apisix-ingress get Pods -l "app.kubernetes.io/name=apisix" -o name) -c apisix -- curl -H "Host: local.httpbin.org" localhost:9080/ip
```

期待される出力は以下の通りです：

```
{
"origin": "127.0.0.1"
}
```

これは、設定が正常に適用されたことを示しています。

### APISIX IngressがGateway APIをサポートする方法

現在、APISIX Ingress ControllerはGateway APIのサポートを追加中であり、HTTPRoute、TCPRouteなどのリソースをサポートしています。

APISIX Ingress ControllerのGatewayおよびGateway Classのサポートは積極的に開発中であるため、これらのリソースの設定は現時点では有効になりません。

## まとめ

この記事では、クラスタ外にサービスを公開するためのコミュニティの新しい仕様であるGateway APIを紹介し、APISIX Ingress Controllerでそれをどのように使用するかを説明しました。

[APISIX Ingress Controller](https://api7.ai/blog/apisix-ingress-integrates-with-service-discovery)でのGateway APIの完全なサポートは、現在積極的に開発中です。

Tags:

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Gateway API](https://api7.ai/tags/gateway-api)

[Kubernetes](https://api7.ai/tags/kubernetes)

Share article link

Share

Related Posts

[![なぜAPISIX Ingress ControllerはNGINX Ingress Controllerよりも優れているのか？](https://static.api7.ai/2023/01/05/63b6900e1d793.png)](https://api7.ai/blog/apisix-ingress-vs-ingress-nginx)

## [なぜAPISIX Ingress ControllerはNGINX Ingress Controllerよりも優れているのか？](https://api7.ai/blog/apisix-ingress-vs-ingress-nginx)

[![APISIX Ingress ControllerがTraefikよりも優れた選択肢である理由](https://static.api7.ai/uploads/2024/09/06/ldwwEzTf_APISIX%20Ingress%20Controller-3.png)](https://api7.ai/blog/apisix-ingress-better-than-traefik)

## [APISIX Ingress ControllerがTraefikよりも優れた選択肢である理由](https://api7.ai/blog/apisix-ingress-better-than-traefik)

Table of Contents

- [Kubernetes Gateway APIとは](#kubernetes-gateway-api%E3%81%A8%E3%81%AF)

  - [Gateway APIが必要な理由](#gateway-api%E3%81%8C%E5%BF%85%E8%A6%81%E3%81%AA%E7%90%86%E7%94%B1)
  - [Gateway APIの現状](#gateway-api%E3%81%AE%E7%8F%BE%E7%8A%B6)

- [APISIX IngressでGateway APIを使用する方法](#apisix-ingress%E3%81%A7gateway-api%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)

  - [Gateway API CRDのインストール](#gateway-api-crd%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB)
  - [APISIX Ingress Controllerのインストール](#apisix-ingress-controller%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB)
  - [テストロードのデプロイ](#%E3%83%86%E3%82%B9%E3%83%88%E3%83%AD%E3%83%BC%E3%83%89%E3%81%AE%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4)
  - [HTTPRouteの設定](#httproute%E3%81%AE%E8%A8%AD%E5%AE%9A)
  - [検証](#%E6%A4%9C%E8%A8%BC)
  - [APISIX IngressがGateway APIをサポートする方法](#apisix-ingress%E3%81%8Cgateway-api%E3%82%92%E3%82%B5%E3%83%9D%E3%83%BC%E3%83%88%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)

- [まとめ](#%E3%81%BE%E3%81%A8%E3%82%81)

## Related Posts

[![なぜAPISIX Ingress ControllerはEmissary-ingressよりも優れた選択肢なのか？](https://static.api7.ai/uploads/2024/12/24/CLpj341F_apisix-ingress-controller-vs-emissary.png)](https://api7.ai/ja/blog/apisix-ingress-vs-emissary-ingress)

Products

March 17, 2023

#### [なぜAPISIX Ingress ControllerはEmissary-ingressよりも優れた選択肢なのか？](https://api7.ai/ja/blog/apisix-ingress-vs-emissary-ingress)

本記事では、APISIX Ingress ControllerとEmissary-ingressのパフォーマンスを、スケーラビリティやサービスディスカバリー統合など、複数の次元から比較しています。

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Kubernetes](https://api7.ai/tags/kubernetes)

[Emissary-Ingress](https://api7.ai/tags/emissary-ingress)

[![APISIX Ingress Controller 与 Service Discovery 集成](https://static.api7.ai/uploads/2024/12/25/yzN9mzLr_apisix-ingress-controller-service-discovery.png)](https://api7.ai/ja/blog/apisix-ingress-integrates-with-service-discovery)

Products

January 13, 2023

#### [APISIX Ingress Controller 与 Service Discovery 集成](https://api7.ai/ja/blog/apisix-ingress-integrates-with-service-discovery)

APISIX Ingress Controller 通过与服务发现（service discovery）集成，降低了微服务（microservices）的部署成本。

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Kubernetes](https://api7.ai/tags/kubernetes)

[Service Discovery](https://api7.ai/tags/service-discovery)

[![如何在Apache APISIX Ingress Controller中代理外部服务](https://static.api7.ai/uploads/2024/12/24/WADOMxsJ_proxy-services-using-ingress-controller.png)](https://api7.ai/ja/blog/proxy-services-in-apisix-ingress-controller)

Products

January 13, 2023

#### [如何在Apache APISIX Ingress Controller中代理外部服务](https://api7.ai/ja/blog/proxy-services-in-apisix-ingress-controller)

APISIX Ingress Controller での外部サービスのプロキシ方法について紹介します。

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Kubernetes](https://api7.ai/tags/kubernetes)
