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?

【簡単Kubernetes】【CKAD向け】Kubernetes ネットワーク初心者向け:Ingress と Service のポート設定のポイント

Posted at

こんにちは。今回は Kubernetes における Ingress と Service のポート設定の違い について、わかりやすく解説します。


🔍 Ingress の port 設定とは?

Ingress の設定では、serviceNameservicePort を指定します。
ここで指定するのは、Ingress がアクセス先の Service を特定するための情報であり、Service の名前とポート番号を指定します。

例:

spec:
  rules:
  - http:
      paths:
      - path: /example
        backend:
          serviceName: my-service    # Service の名前
          servicePort: 80            # Service のポート番号(targetPort ではありません)

この servicePort は、Service の spec.ports[].port に対応しています。


⚙️ Service の port と targetPort の違い

Service は複数のポート情報を持っていて、主に以下の2つがあります。

  • port:Service がクラスター内で公開するポート
  • targetPort:Service がリクエストを転送する Pod のコンテナポート。
    たいていは Deployment の containerPort と同じ番号を指定します。

例:

spec:
  ports:
  - port: 80            # Service のポート(Ingress の servicePort と一致)
    targetPort: 8080    # Pod のコンテナがリッスンしているポート(containerPort)

📦 Deployment の containerPort

Pod 内のコンテナが実際にリッスンしているポートです。
Service の targetPort がこの containerPort に対応します。

containers:
- name: my-app
  image: my-app-image
  ports:
  - containerPort: 8080    # コンテナの実際のポート

📝 まとめ

設定箇所 ポート名 説明
Ingress servicePort Service の port を指定する
Service port クラスター内で公開するポート(Ingress から指定される)
targetPort Pod の containerPort に転送するポート
Deployment (Pod) containerPort コンテナが実際にリッスンしているポート

💡 ポイント

  • Ingress は Service の port にトラフィックを流すため、targetPort や Pod の containerPort は直接指定しません。
  • Service がリクエストを受けてから、targetPort を使って Pod のコンテナに転送します。
  • つまり、
    Ingress → Service(port) → Service(targetPort) → Pod(containerPort)
    という流れになります。

今回の内容が Kubernetes ネットワーク設定の理解に役立てば幸いです。
ご質問やフィードバックがあれば、ぜひコメントしてくださいね 😊

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?