Docker & Kubernetes for Developers · Ders

K8s'te hizmet keşfi ve DNS

Kubernetes'in hizmet keşfini ve hizmetler arası iletişim için DNS çözümlemesini nasıl yönettiğini keşfedin.

3. ders / 411 adım

K8s'te hizmet keşfi ve DNS, CoddyKit'te ücretsiz bir Docker & Kubernetes for Developers dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Docker & Kubernetes for Developers öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Docker & Kubernetes for Developers kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Intro to Service Discovery

Welcome to Service Discovery & DNS in K8s! In a dynamic Kubernetes cluster, Pods are constantly created, destroyed, and moved, leading to ever-changing IP addresses.

How do applications running in one Pod find and communicate with applications in another Pod or Service?

This is where Service Discovery comes in. It's how services find each other without needing to know their specific, ephemeral IP addresses.

The Role of DNS in K8s

You might already know about DNS (Domain Name System) on the internet. It translates human-readable names like google.com into IP addresses.

Kubernetes uses a similar concept internally. Instead of relying on unstable Pod IPs, K8s assigns stable DNS names to its Services.

This allows your applications to connect to other services using simple, consistent names.

CoreDNS: The K8s DNS Server

Every Kubernetes cluster comes with its own DNS server, typically CoreDNS (or sometimes kube-dns in older versions).

CoreDNS runs as a Pod within your cluster and is responsible for resolving all internal Kubernetes service names to their corresponding cluster IP addresses.

It's automatically configured for you when you set up your cluster.

How Pods Get DNS Config

When a Pod starts, Kubernetes automatically injects DNS configuration into it.

  • Each Pod's /etc/resolv.conf file is updated to point to the cluster's CoreDNS Service IP.
  • It also includes search paths, allowing you to use shorter service names.

This means any application inside a Pod can immediately use the cluster's DNS for name resolution.

Service DNS Names

When you create a Kubernetes Service (e.g., a ClusterIP Service), CoreDNS automatically creates a DNS record for it.

The most common format for a Service's DNS name within its own namespace is simply: <service-name>.

For example, a service named my-web-app in the default namespace can be reached by other Pods in the same namespace using just my-web-app.

Example: Same-Namespace Access

Let's say you have a deployment hello-app and a service hello-service in the default namespace. Any other Pod in default can reach it via hello-service.

Here's a simple example of a Deployment and Service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-app
spec:
  selector:
    matchLabels:
      app: hello
  replicas: 1
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello-container
        image: busybox
        command: ["sh", "-c", "while true; do echo Hello K8s; sleep 5; done"]

---

apiVersion: v1
kind: Service
metadata:
  name: hello-service
spec:
  selector:
    app: hello
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP

Testing Same-Namespace DNS

After applying the YAML from the previous scene, you can test service discovery. First, create a temporary Pod (e.g., debug-pod) in the same namespace.

Then, exec into debug-pod and try to ping the service:

  • kubectl run debug-pod --image=busybox --restart=Never --rm -it --command -- sh
  • Inside the pod: ping hello-service

You should see the hello-service ClusterIP being resolved!

Cross-Namespace DNS (FQDN)

What if your services are in different namespaces? Kubernetes uses a Fully Qualified Domain Name (FQDN) format:

<service-name>.<namespace-name>.svc.cluster.local

For convenience, if the Pod's namespace is in its DNS search path (which it usually is), you can often use a shorter form:

<service-name>.<namespace-name>

This allows clear and unambiguous communication across different parts of your application.

Example: Cross-Namespace Access

Let's imagine a backend-service in the prod namespace. From a Pod in the default namespace, you'd access it like this:

ping backend-service.prod

Kubernetes DNS handles the resolution, directing traffic to the correct service, even across namespaces.

This provides strong isolation while still enabling communication where needed.

Quick Check

Which of the following statements are TRUE regarding Kubernetes Service Discovery and DNS?

Recap: Service Discovery & DNS

Great job! In this lesson, you learned how Kubernetes handles service discovery and DNS resolution for internal communication:

  • Pods have ephemeral IPs, requiring a stable discovery mechanism.
  • CoreDNS is the cluster's internal DNS server.
  • Services get stable DNS names, resolvable by other Pods.
  • Pods are automatically configured to use the cluster's DNS.
  • You can access services in the same namespace by name or in other namespaces using FQDNs.

This powerful system ensures your applications can always find each other reliably!

Başlamak ücretsiz

Yapay zeka eğitmeniyle Docker & Kubernetes for Developers öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“K8s'te hizmet keşfi ve DNS” dersi ücretsiz mi?

Evet — “K8s'te hizmet keşfi ve DNS” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Docker & Kubernetes for Developers kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Docker & Kubernetes for Developers kursu toplamda 4 dersten oluşur.

“K8s'te hizmet keşfi ve DNS” dersinde ne öğreneceğim?

Kubernetes'in hizmet keşfini ve hizmetler arası iletişim için DNS çözümlemesini nasıl yönettiğini keşfedin. Docker & Kubernetes for Developers ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Docker & Kubernetes for Developers öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Docker & Kubernetes for Developers, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“K8s'te hizmet keşfi ve DNS” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Docker & Kubernetes for Developers dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Docker & Kubernetes for Developers dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Kubernetes Ingress ve yönlendirme
  2. Ağ politikalarını uygulama
  3. K8s'te hizmet keşfi ve DNS
  4. TLS Sonlandırma ve Ingress'i HTTPS ile Güvenceye Alma
← Docker & Kubernetes for Developers Sayfasına Dön