CISを用いたオンプレミスKubernetesクラスタのService公開について - Part 2

はじめに

今回の記事ではIngressとしてBIG-IPを用いて実際にServiceを公開していきます。
前回の記事でCISのデプロイ手順を解説していますので、完了していない場合はまずそちらを実施の上で進めて下さい。

【前回の記事】
CISを用いたオンプレミスKubernetesクラスタのService公開について - Part 1

CISのService公開オプション

CISでServiceを公開する場合のオプションはいくつかありますが、今回の例ではIngressを用いて設定します。
各公開オプションに関する特徴は以下となります。

  • Ingress
    Serviceを指定してIngressリソースをデプロイすることで、CISによってL7ロードバランス設定が作成されます。
    設定内容に伴い、L7パスベースルーティングやSSL終端をBIG-IPで実施します。
  • Service Type Loadbalancer
    Serviceをtype: Loadbalancerでデプロイすることで、CISによってL4ロードバランス設定が作成されます。
    L7ベースのルーティングを行いたい場合、別途Ingress Controllerの展開が必要となります。
  • Configmap
    Serviceをデプロイする際に、事前に設定したConfigmapをlabelで紐づけることでL4/L7ロードバランス設定を作成します。
    ConfigmapはAS3によって設定しますので、他の公開オプションと比べて多くの設定パラメータに対応しています。
    また、複数のBIG-IP Partitionに分けて設定を投入することも可能です。
  • Custom Resource Definitions(CRDs)
    CIS用に用意されたCustom Resource Definitions(CRDs)を用いてL4/L7ロードバランス設定を作成します。
    他の公開オプションと比べて、より直感的にBIG-IPの設定を記載可能です。

Ingressリソースの設定手順

手順1. 公開対象のDeploymentとServiceを展開
まずは公開対象とするDeploymentとServiceを展開します。
下記のManifestを"f5-hello-world.yaml"ファイルに保存して下さい。
Deployment "f5-hello-world" では、コンテナイメージとしてnginxを指定してreplica数を3に設定しています。
Service "f5-hello-world-svc"では、f5-hello-world DeploymentをnodePortで公開するように設定しています。

 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: f5-hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: f5-hello-world
  template:
    metadata:
      labels:
        app: f5-hello-world
    spec:
      containers:
        - name: f5-hello-world
          image: nginx:stable

---

apiVersion: v1
kind: Service
metadata:
  name: f5-hello-world-svc
spec:
  ports:
  - name: f5-hello-world-web
    port: 80
    protocol: TCP
  type: NodePort
  selector:
    app: f5-hello-world

 

f5-hello-world.yamlファイルを以下のコマンドで展開します。

# kubectl apply -f f5-hello-world.yaml
deployment.apps/f5-hello-world created
service/f5-hello-world-svc created

 手順2. Ingressリソースの設定
続いてIngressリソースを展開します。
下記のManifestを"f5-hello-world.yaml"ファイルに保存して下さい。
annotation "virtual-server.f5.com"の各パラメータは以下の内容で設定してください。

virtual-server.f5.com/partition      : 手順1で設定したBIG-IPのPartition名を入力して下さい。
virtual-server.f5.com/ip                 : Virtual ServerのIPアドレスを入力して下さい。
virtual-server.f5.com/http-port     : Virtual Serverのポート番号を入力して下さい。
virtual-server.f5.com/ssl-redirect : HTTPトラフィックの場合、HTTPSにリダイレクトさせるための設定です。
                今回はHTTPトラフィックで検証を行うためfalseに設定します。
virtual-server.f5.com/health
   : ヘルスチェックに関するパラメータを設定します。

Spec内ではL7パスベースルーティングの設定を行います。
URLパスに対して、任意のServiceへルーティングを行う事が可能です。

 

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: f5-hello-world-web
  namespace: default
  annotations:
    virtual-server.f5.com/partition: "kubernetes"
    virtual-server.f5.com/ip: 10.1.1.4
    virtual-server.f5.com/http-port: "80"
    virtual-server.f5.com/ssl-redirect: "false"
    virtual-server.f5.com/health: |
      [
        {
          "path":     "f5.hello.world/",
          "send":     "HTTP GET /",
          "interval": 5,
          "timeout":  10
        }
      ]
spec:
  ingressClassName: f5
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: f5-hello-world-svc
            port:
              number: 80

 

ingress-f5-hello-world.yamlファイルを以下のコマンドで展開します。

# kubectl apply -f ingress-hello-world-web.yml
ingress.networking.k8s.io/f5-hello-world-web created

 手順3. BIG-IPの設定を確認
BIG-IPのkubernetes Partitionに設定した内容に伴い、設定が作成されている事を確認します。
今回の環境ではWorker Nodeとして172.28.14.108、172.28.14.109、172.28.14.110が動作しておりpoolとして登録されました。




まとめ
以上の手順でIngressリソースの設定は終了となります。
次回の記事では、CISとNGINX Ingress Controllerを組み合わせた場合の設定について解説していきます。

Updated Jul 12, 2022
Version 3.0

Was this article helpful?

No CommentsBe the first to comment