仮想ノードを使用したOCI KubernetesエンジンでのOCIネイティブ・イングレス・コントローラの設定

はじめに

このチュートリアルでは、Oracle Cloud Infrastructure Kubernetes Engine (OKE)に仮想ノード・ノード・プールを使用してOracle Cloud Infrastructure (OCI)ネイティブ・イングレス・コントローラを設定するプロセスについて説明します。仮想ノードは、基礎となるコンピュート・インスタンスを抽象化するサーバーレス・ソリューションであるため、通常のインスタンスベースのワーカー・ノードとは異なります。特定の仮想マシン・インスタンスに依存する従来のワーカー・ノードとは異なり、仮想ノードはワークロードの要求に基づいて動的にスケーリングされるため、基礎となるインフラストラクチャの手動管理は必要ありません。これにより、自動スケーリングおよび運用オーバーヘッドの削減を必要とするワークロードに最適です。

このチュートリアルでは、仮想ノードを使用して、OKEにOCIネイティブ・イングレス・コントローラを設定します。ワークロード・アイデンティティ・ポリシーを構成し、イングレス・アドオンを有効にし、Kubernetesマニフェストを使用してイングレス・リソースをデプロイします。

これらのタスクに従うことで、仮想ノードの運用上のシンプルさを活用しながら、OCIロード・バランサ機能を使用してアプリケーションを公開し、イングレス・トラフィックを管理できます。この設定により、トラフィック管理が合理化され、スケーラブルでコスト効率の高い方法で本番レベルのワークロードがサポートされます。

目的

タスク1: ワークロード・アイデンティティ・プリンシパル・ポリシーの作成

OCIネイティブ・イングレス・コントローラを有効にする前に、ワークロード・アイデンティティ・プリンシパル・ポリシーを作成します。仮想ノードはサーバーレスであり、OCIコンピュート・インスタンスを使用しないため、インスタンス・プリンシパルのかわりにワークロードIDが必要です。このポリシーにより、イングレス・コントローラはコンパートメント内のリソースを管理できます。

  1. OCIコンソールに移動し、「アイデンティティとセキュリティ」「アイデンティティ」に移動して、「ポリシー」をクリックします。

  2. ポリシーを作成し、ポリシー名を入力します。詳細は、OCIコンソールを使用したポリシーの作成を参照してください。

  3. 「手動エディタの表示」をクリックし、locationおよびcluster-ocidを特定の値に置き換えて、次のポリシー・ステートメントを入力します。

    ノート:

    • <location>は、リソースが存在するコンパートメントに置き換える必要があります。
    • <cluster-ocid>は、OKEクラスタのOCIDに置き換えてください。
    Allow any-user to manage load-balancers in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to use virtual-network-family in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage cabundles in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage cabundle-associations in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage leaf-certificates in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to read leaf-certificate-bundles in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage leaf-certificate-versions in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage certificate-associations in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to read certificate-authorities in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage certificate-authority-associations in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to read certificate-authority-bundles in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to read public-ips in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage floating-ips in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to manage waf-family in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to read cluster-family in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    
    Allow any-user to use tag-namespaces in <location> where all {request.principal.type = 'workload', request.principal.namespace = 'native-ingress-controller-system', request.principal.service_account = 'oci-native-ingress-controller', request.principal.cluster_id = '<cluster-ocid>'}
    

タスク2: OCIネイティブ・イングレス・コントローラ・アドオンの有効化

必要なワークロード・アイデンティティ・プリンシパル・ポリシーが設定されたら、OKEクラスタでOCIネイティブ・イングレス・コントローラ・アドオンを有効にできます。このアドオンを使用すると、OCIロード・バランサを使用してイングレス・トラフィックを効率的に管理できます。

  1. OCIコンソールでOKEクラスタに移動します。

  2. 下へスクロールして、「アドオン」をクリックします。

  3. 「アドオン」ページで、「ネイティブ・イングレス・コントローラ」をクリックします。

  4. 「ネイティブ・イングレス・コントローラの編集」ページで、「ネイティブ・イングレス・コントローラの有効化」を選択し、「オプション」の下に次の情報を入力します。

    • compartmentId:コンパートメントOCIDを入力します。
    • loadBalancerSubnetId:ロード・バランサ・サブネットOCIDを入力します。
    • authType: workloadIdentityと入力します。
  5. 「変更の保存」をクリックして、設定を適用します。

    ノート:この構成は、前述の仮想ノード・プールではサーバーレスであり、インスタンス・プリンシパル認証をサポートしていません。この場合、ワークロード・アイデンティティがサポートされている認証方法です。

    ネイティブ・イングレス・アドオン

タスク3: イングレス・リソースのデプロイによるネイティブ・イングレス機能の有効化

このタスクでは、OCIネイティブ・イングレス・コントローラを使用してイングレス機能を有効にするために必要なKubernetesリソースを作成します。これには、IngressClassParametersIngressClassおよび実際のIngressオブジェクトが含まれます。

  1. 各リソースの目的を確認します。

    • IngressClassParameters:コンパートメントOCID、サブネット、帯域幅などのOCI固有の構成を指定します。
    • IngressClass: Kubernetesイングレス機能をOCIのイングレス・コントローラにリンクします。
    • イングレス:トラフィックをサービスにルーティングする方法を定義します。
  2. YAMLのプレースホルダ値を置換します。

    • <your compartment ocid>を実際のコンパートメントOCIDに置き換えます。
    • <your load balancer subnet ocid>ロード・バランサ・サブネットのOCIDに置き換えます。
  3. YAMLマニフェストを適用します。次のYAMLコードをファイル(native-ingress.yamlなど)に保存します。

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test-web-app
      namespace: default
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: test-web
      template:
        metadata:
          labels:
            app: test-web
        spec:
          containers:
          - name: nginx
            image: nginx:latest
            ports:
            - containerPort: 80
            readinessProbe:
              httpGet:
                path: /
                port: 80
              initialDelaySeconds: 3
              periodSeconds: 5
            resources:
              requests:
                cpu: "100m"
                memory: "128Mi"
              limits:
                cpu: "500m"
                memory: "256Mi"
    
    apiVersion: v1
    kind: Service
    metadata:
      name: test-web-service
      namespace: default
    spec:
      selector:
        app: test-web
      ports:
        - protocol: TCP
          port: 80
          targetPort: 80
    
    apiVersion: ingress.oraclecloud.com/v1beta1
    kind: IngressClassParameters
    metadata:
      name: native-ic-params
      namespace: native-ingress-controller-system
    spec:
      compartmentId: "ocid1.compartment.oc1..aaaaaaaa2eimxxxxxxxxxxz4lkcety52hfdg6wdoff6744yn4hrshofla"
      subnetId: "ocid1.subnet.oc1.iad.aaaaaaaaa72ie4xxxxxxxxxrxxrly6nmkb77qxt6mi2t5pvrdhge32q"
      loadBalancerName: "test-web-ingress"
      isPrivate: false
      maxBandwidthMbps: 400
      minBandwidthMbps: 100
    
    apiVersion: networking.k8s.io/v1
    kind: IngressClass
    metadata:
      name: native-ic-ingress-class
      annotations:
        ingressclass.kubernetes.io/is-default-class: "true"
    spec:
      controller: oci.oraclecloud.com/native-ingress-controller
      parameters:
        apiGroup: ingress.oraclecloud.com
        kind: IngressClassParameters
        name: native-ic-params
        scope: Namespace
        namespace: native-ingress-controller-system
    
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: test-web-ingress-quickstart
      namespace: default
      annotations:
        oci.oraclecloud.com/load-balancer-type: "lb"
        oci.oraclecloud.com/healthcheck-protocol: "HTTP"
        oci.oraclecloud.com/healthcheck-port: "80"
        oci.oraclecloud.com/healthcheck-path: "/"
        oci.oraclecloud.com/healthcheck-return-code: "200"
    spec:
      ingressClassName: native-ic-ingress-class
      rules:
      - host: test.example.com
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: test-web-service
                port:
                  number: 80
      - http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: test-web-service
                port:
                  number: 80
    
  4. 次のコマンドを実行して、マニフェストを適用します。

    kubectl apply -f native-ingress.yaml
    
  5. リソースの作成を確認します。

    kubectl get ingressclassparameters
    kubectl get ingressclass
    kubectl get ingress
    

タスク4: OCIネイティブ・イングレス・コントローラ・ロード・バランサのテスト

ノート: OCIロード・バランサのIPアドレスをテストする前に、必要なポート(80443など)がVCNのセキュリティ・リストまたはネットワーク・セキュリティ・グループ(NSG)(あるいはその両方)で開いていることを確認してください。

OCIネイティブ・イングレス・コントローラが正しく動作していることを確認するには、次のステップを実行します。

  1. kubectlを使用して、イングレス・リソースのIPアドレスを取得します。

    kubectl get ingress
    
  2. 出力に表示されているIPアドレスをコピーします。

    kubectl

  3. Webブラウザを開き、アドレス・バーにIPアドレスを貼り付けます。

    Nginx

  4. 設定が正しい場合は、デプロイされたサービスからのデフォルトのレスポンスが表示されます。

    また、ナビゲーション・メニューに移動して「ネットワーキング」を選択し、「ロード・バランサ」をクリックして、OCIコンソールでOCIロード・バランサが正しく作成されたことを確認することもできます。

    ロンドン

次のステップ

このチュートリアルでは、仮想ノードを使用してOKEでネイティブ・イングレス・コントローラを正常に構成しました。この設定により、OCIロード・バランサ・サービスでイングレス・トラフィックを管理しながら、サーバーレスKubernetes環境のスケーラビリティとシンプルさの恩恵を受けることができます。これで、合理化されたトラフィック管理とインフラストラクチャのオーバーヘッドを最小限に抑えながら、本番レベルのワークロードをデプロイする準備ができました。

確認

その他の学習リソース

docs.oracle.com/learnで他のラボを確認するか、Oracle Learning YouTubeチャネルで無料のラーニング・コンテンツにアクセスしてください。また、education.oracle.com/learning-explorerにアクセスして、Oracle Learning Explorerになります。

製品ドキュメントについては、Oracle Help Centerを参照してください。