Linux Networking & TCP/IP for Developers · レッスン

KubernetesにおけるサービスディスカバリとDNS

コンテナ同士が互いを見つける仕組みを学びます。クラスタDNS、Serviceオブジェクト、マイクロサービスを名前で参照可能にする名前解決の流れを扱います。

レッスン 4/413 ステップ

「KubernetesにおけるサービスディスカバリとDNS」はCoddyKit上の無料Linux Networking & TCP/IP for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLinux Networking & TCP/IP for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Linux Networking & TCP/IP for Developersコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

The Discovery Problem

Container IPs are ephemeral — pods restart and get new addresses constantly. Hardcoding IPs is impossible.

Service discovery lets workloads find each other by stable names instead of changing IPs.

The Service Abstraction

A Kubernetes Service provides a stable virtual IP (ClusterIP) and DNS name that load-balances across a set of pods selected by labels.

apiVersion: v1
kind: Service
metadata:
  name: orders
spec:
  selector:
    app: orders
  ports:
    - port: 80

Cluster DNS

Every cluster runs a DNS server (CoreDNS). It automatically creates records for each Service so workloads can resolve them by name.

The DNS Naming Scheme

Services follow a predictable FQDN pattern:

service.namespace.svc.cluster.local

Within the same namespace, just orders works. Across namespaces use orders.payments.

curl http://orders.payments.svc.cluster.local

How a Pod Resolves Names

Each pod's /etc/resolv.conf points at the cluster DNS and includes search domains, so short names expand to full Service FQDNs automatically.

cat /etc/resolv.conf

ClusterIP Load Balancing

A ClusterIP is virtual — kube-proxy programs iptables or IPVS rules so traffic to it is distributed across the healthy backing pods. Clients never see individual pod IPs.

Headless Services

Set clusterIP: None for a headless Service. DNS then returns the individual pod IPs directly, which is ideal for stateful sets and client-side load balancing.

spec:
  clusterIP: None
  selector:
    app: db

Endpoints and EndpointSlices

Behind each Service, Kubernetes maintains EndpointSlices listing the ready pod IPs. As pods come and go, these update so DNS and routing stay current.

kubectl get endpointslices

Resolving from Inside a Pod

You can debug discovery by running nslookup from a pod to verify a Service name resolves to its ClusterIP.

kubectl exec -it shell -- nslookup orders

External Name Services

An ExternalName Service maps a cluster DNS name to an outside hostname via a CNAME, letting you reference external systems with cluster-internal names.

spec:
  type: ExternalName
  externalName: api.example.com

Common Discovery Failures

When name resolution fails, check:

  • Label selector mismatch (no endpoints)
  • Wrong namespace in the FQDN
  • CoreDNS pods unhealthy
  • NetworkPolicy blocking DNS (port 53)

Quick Check

Test your service discovery knowledge.

Recap

You now understand container service discovery:

  • Services give stable ClusterIPs and DNS names
  • CoreDNS resolves service.namespace.svc.cluster.local
  • EndpointSlices track ready pods
  • Headless and ExternalName Services for special cases
  • Debug with nslookup from inside pods

This builds on your Docker network modes and Kubernetes networking basics.

無料で開始

AI チューターと学ぶ Linux Networking & TCP/IP for Developers — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
12
レッスン
48

よくある質問

「KubernetesにおけるサービスディスカバリとDNS」レッスンは無料ですか?

はい。「KubernetesにおけるサービスディスカバリとDNS」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Linux Networking & TCP/IP for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Linux Networking & TCP/IP for Developersコースには全4レッスンが含まれています。

「KubernetesにおけるサービスディスカバリとDNS」で何を学びますか?

コンテナ同士が互いを見つける仕組みを学びます。クラスタDNS、Serviceオブジェクト、マイクロサービスを名前で参照可能にする名前解決の流れを扱います。 ブラウザで直接実行するハンズオンコードでLinux Networking & TCP/IP for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Linux Networking & TCP/IP for Developersを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLinux Networking & TCP/IP for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「KubernetesにおけるサービスディスカバリとDNS」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLinux Networking & TCP/IP for Developersレッスンでコードを書いて実行できますか?

はい。すべてのLinux Networking & TCP/IP for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Dockerのネットワークモード
  2. Kubernetesネットワーキングの基礎
  3. コンテナのネットワークポリシー
  4. KubernetesにおけるサービスディスカバリとDNS
← Linux Networking & TCP/IP for Developersに戻る