--- title: "Load Balancerプロパティ設定のユースケース" slug: "k8s-k8sexamples-loadbalancer" tags: ["Load Balancer", "Ncloud Kubernetes Service", "vpc"] updated: 2026-09-17T09:31:49Z published: 2026-09-17T09:31:49Z canonical: "guide.ncloud-docs.com/k8s-k8sexamples-loadbalancer" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://guide.ncloud-docs.com/llms.txt > Use this file to discover all available pages before exploring further. # Load Balancerプロパティ設定のユースケース VPC環境で利用できます。 [Load Balancerインスタンスの連携](/docs/ja/k8s-k8suse-loadbalancer)で紹介した各種アノテーションを活用して Load Balancerインスタンスのプロパティを設定するユースケースです。 注意 Kubernetesで作成した NAVERクラウドプラットフォームのロードバランサを Kubernetesの Serviceリソースではなくコンソールや APIを通じて設定する場合、状態の同期に問題が発生します。作成されたロードバランサに関する設定の変更は、必ず Kubernetesで作成された Serviceリソースを変更して行ってください。 ## ユースケース ロードバランサの作成時に共通して使用できる設定の例です。 ### Load Balancer Class選択のユースケース Kubernetes 1.27バージョン以降から `LoadBalancerClass`を指定することができます。LoadBalancerClassを指定することで NAVERクラウドプラットフォームが提供するロードバランサ以外のロードバランサをクラスタで使用できます。これにより、LoadBalancerClassの指定時に Network Load Balancerや Network Proxy Load Balancerは作成されません。サービスの作成後には、割り当てられた External-IPを確認し、外部からアクセスできることを確認する必要があります。下記の例は、[loxilb](https://github.com/loxilb-io/loxilb)を Load BalancerClassに指定して使用する方法を説明します。 ``` apiVersion: v1 kind: Service metadata: name: my-nginx labels: app: nginx spec: selector: app: nginx ports: - port: 8765 targetPort: 80 type: LoadBalancer loadBalancerClass: "loxilb.io/loxilb" ``` ### インスタンスが作成される専用サブネット選択のユースケース インスタンスの作成時、`kube-system`Namespaceで `ncloud-config`という名前の `configmap`内の `lbSubnetNo`をデフォルトで使用します。他のロードバランサ専用のサブネットにインスタンスを作成する必要がある場合は、`service.beta.kubernetes.io/ncloud-load-balancer-subnet-id` アノテーションを使用できます。 以下は、NPLBインスタンスが作成される専用サブネットを選択するユースケースです。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-subnet-id: "452772" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### ロードバランサのパブリック IPアドレス付与のユースケース `LoadBalancer` タイプの Serviceの場合、`spec.loadBalancerIP` フィールドにロードバランサに割り当てるパブリック IPアドレスを定義できます。このフィールドには **NAVERクラウドプラットフォームコンソール > VPC > Public IP**メニューから確認できる未割り当てのパブリック IPアドレスのみ記述できます。 基本的にロードバランサを削除すると、割り当てられたパブリック IPアドレスも一緒に返却されます。パブリック IPアドレスが一緒に返却されないように `service.beta.kubernetes.io/ncloud-load-balancer-retain-public-ip-on-termination: "true"` annotationを使用できます。 ``` apiVersion: v1 kind: Service metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-retain-public-ip-on-termination: "true" spec: loadBalancerIP: 110.234.194.181 ports: - port: 80 targetPort: 8080 protocol: TCP name: http selector: run: nginx type: LoadBalancer ``` ### プライベートネットワークタイプのロードバランサ作成のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-internal` アノテーションを用いて、VPC内部でのみアクセスできるプライベートタイプのロードバランサを作成できます。このアノテーションのデフォルト値は falseなので、明示的に指定しないとパブリックタイプのロードバランサが作成されます。プライベートタイプのロードバランサは、VPC内部のプライベート IPアドレスを利用して内部サーバ間の負荷を分散処理し、VPC外部からのアクセスは許可されません。 ``` apiVersion: v1 kind: Service metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-internal: "true" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### 負荷分散アルゴリズム設定のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-algorithm-type-code`アノテーションを用いて、ロードバランサの負荷分散アルゴリズムを設定することができます。Network Proxy LoadBalancerの場合は Round Robin(RR)、Source Ip Hash(SIPHS)、Least Connection(LC)の中から選択でき、Network LoadBalancerの場合は Hash(MH)、Round Robin(RR)の中から選択できます。 以下は、Network Proxy LoadBalancerを作成しながら、負荷分散アルゴリズムとして Source Ip Hash(SIPHS)を選択する例です。 ``` apiVersion: v1 kind: Service metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-algorithm-type-code: "SIPHS" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### Access Control List設定のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-listener-acl-id.{port}: {aclId}` アノテーションを使用してロードバランサリスナー別に Access Control Listを設定できます。 以下は、そのアノテーションを用いて Access Control Listを設定するユースケースです。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-listener-acl-id.80: "123" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ## ネットワークプロキシロードバランサ(NPLB)プロパティ設定のユースケース ### ネットワークプロキシロードバランサ(NPLB)インスタンス作成のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-layer-type`アノテーションを用いて、NetworkProxyLoadBalancerインスタンスを作成できます。以下は NetworkProxyLoadBalancerインスタンス作成のユースケースです。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-internal: "true" service.beta.kubernetes.io/ncloud-load-balancer-size: "SMALL" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### ロードバランサの負荷処理性能設定のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-size` アノテーションを用いて作成したロードバランサの負荷処理性能を設定できます。 以下は、そのアノテーションを用いて負荷処理性能を設定するユースケースです。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-size: "MEDIUM" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### TLS設定のユースケース サービス明細を通じて、TLS/SSL証明書をロードバランサに適用できます。Certificate Managerに登録された証明書番号(nrn)を `service.beta.kubernetes.io/ncloud-load-balancer-ssl-certificate-no`に指定し、TLSを使用するポート番号を service.beta.`service.beta.kubernetes.io/ncloud-load-balancer-tls-ports`アノテーションに設定します。以下は、443ポート(HTTPS)に入るトラフィックを暗号化して80ポート(HTTP)に転送するユースケースです。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-ssl-certificate-no: "1234" service.beta.kubernetes.io/ncloud-load-balancer-tls-ports: "443" spec: ports: - port: 443 targetPort: 80 selector: app: nginx type: LoadBalancer ``` ### プロキシプロトコル有効化のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-proxy-protocol` アノテーションにより、ロードバランサのプロキシプロトコルを有効にすることができます。プロキシプロトコルは、TCPや SSLプロトコルを使用する際に、プロキシ環境を通じて接続リクエストをするクライアントのソース IPアドレス(Original Client IP address)を知ることができるプロトコルです。この機能を使うためには、ロードバランサだけでなく、接続されたアプリケーション(Pod)でも関連設定をする必要があります。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-proxy-protocol: "true" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### ロードバランサ Idle Timeout設定のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-idle-timeout` により、ロードバランサの Idle Timeoutを調整することができます。アプリケーションの Idle Timeoutを考慮して調整する必要があり、ロードバランサのデフォルト値は60秒です。以下の例は、ロードバランサの Idle Timeout値を90秒に設定する方法を示しています。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nplb" service.beta.kubernetes.io/ncloud-load-balancer-idle-timeout: "90" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ## ネットワークロードバランサ(NLB)プロパティ設定のユースケース ### ネットワークロードバランサ(NLB)インスタンス作成のユースケース `service.beta.kubernetes.io/ncloud-load-balancer-layer-type`アノテーションを用いて、NetworkLoadBalancerインスタンスを作成できます。以下は NetworkLoadBalancerインスタンス作成のユースケースです。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nlb" service.beta.kubernetes.io/ncloud-load-balancer-internal: "true" service.beta.kubernetes.io/ncloud-load-balancer-size: "SMALL" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### ロードバランサの作成時、ACGルールの Inbound Source設定のユースケース Serviceタイプが `LoadBalancer`の場合、外部との通信のために Inbound Sourceに `0.0.0.0./0`の ACGルールがデフォルトで設定されます。他の IP Blockをアクセスソースとして設定する場合は、`service.beta.kubernetes.io/ncloud-load-balancer-inbound-source`のアノテーションを使用できます。複数の Inbound Sourceを設定する場合は、コンマ(,)で区切って入力できます。 以下は、NLBインスタンス作成時に ACGルールの Inbound Sourceを設定するユースケースです。 ``` kind: Service apiVersion: v1 metadata: name: my-nginx annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nlb" service.beta.kubernetes.io/ncloud-load-balancer-inbound-source: "10.120.0.0/16,143.248.12.77/32" spec: ports: - port: 80 targetPort: 80 selector: run: my-nginx type: LoadBalancer ``` ### ロードバランサ作成時 UDP設定のユースケース Network LoadBalancerは UDPプロトコルをリスナーとして使用できます。NLBインスタンスの作成時、UDPリスナーを設定する例は次の通りです。 参考 - UDPプロトコルをリスナーに使用してもターゲットグループのヘルスチェックは TCPで行うため、Kubernetesサービスリソースに TCPポートが開かれている必要があります。 - UDPポートと TCPポートが同じ場合には、別途設定は必要ありません。 - UDPポートと TCPポートが異なる場合には、アノテーションを通じてヘルスチェックポートを明示的に指定する必要があります。 - 制限事項によりロードバランサには TCPリスナーも一緒に作成されます。 - UDPと TCPポートが同じ場合 - アノテーションを使用しない ``` apiVersion: v1 kind: Service metadata: name: udp-service annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nlb" spec: selector: app: udp-service ports: - name: tcp port: 80 protocol: TCP nodePort: 30080 - name: udp port: 80 protocol: UDP nodePort: 30080 type: LoadBalancer ``` - UDPと TCPポートが同じでない場合 - アノテーションを通じてヘルスチェックポートの指定必要 ``` apiVersion: v1 kind: Service metadata: name: udp-service annotations: service.beta.kubernetes.io/ncloud-load-balancer-layer-type: "nlb" service.beta.kubernetes.io/ncloud-load-balancer-healthcheck-port.90: "85" #ポート90のヘルスチェックはポート85のノードポートを使用 spec: selector: app: udp-service ports: - name: tcp port: 85 targetPort: 80 protocol: TCP nodePort: 30091 - name: udp port: 90 targetPort: 90 protocol: UDP nodePort: 30090 type: LoadBalancer ```