<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged localhost</title>
<link>https://coderlegion.com/tag/localhost</link>
<description>Powered by Question2Answer</description>
<item>
<title>DNS: The phonebook of the internet.</title>
<link>https://coderlegion.com/11450/dns-the-phonebook-of-the-internet</link>
<description>&lt;p&gt;One‑line: DNS = the phonebook of the internet.&lt;/p&gt;
&lt;p&gt;Two‑words: Name‑resolution.&lt;/p&gt;
&lt;p&gt;Business analogy: Instead of memorizing everyone’s phone number, you look up their name in a directory — DNS is that directory for computers.&lt;/p&gt;
&lt;p&gt;Mechanical definition (tight, clean)&lt;br&gt;
DNS (Domain Name System) converts human‑friendly names into machine‑friendly IP addresses.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;p&gt;google.com → 142.250.72.14&lt;br&gt;
kafka.svc.cluster.local → the pod’s internal cluster IP&lt;br&gt;
elasticsearch.default.svc.cluster.local → the StatefulSet’s service IP&lt;/p&gt;
&lt;h3 id=&quot;you-type-the-name-dns-returns-the-ip-your-app-connects-&quot;&gt;You type the name → DNS returns the IP → your app connects.&lt;/h3&gt;
&lt;p&gt;Why it matters for Docker vs Kubernetes&lt;/p&gt;
&lt;h2 id=&quot;docker-single-host-&quot;&gt;Docker (single host)&lt;/h2&gt;
&lt;p&gt;Containers can cheat and use localhost&lt;br&gt;
DNS barely matters because everything shares one machine&lt;/p&gt;
&lt;h2 id=&quot;kubernetes-multi-node-&quot;&gt;Kubernetes (multi‑node)&lt;/h2&gt;
&lt;p&gt;Pods move&lt;br&gt;
IPs change&lt;br&gt;
Nodes change&lt;br&gt;
Restarts happen&lt;/p&gt;
&lt;p&gt;So the only stable way to reach anything is through DNS names, not IPs or localhost.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka:9092
zookeeper:2181
elasticsearch:9200
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or in full cluster form:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka.svc.cluster.local:9092
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The rule for distributed systems&lt;br&gt;
If you can’t reach it by DNS, you don’t have a real distributed system yet.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;One‑line: Here are the exact DNS names and the Docker‑side simulation.&lt;/p&gt;
&lt;p&gt;Two‑words: Cluster realism.&lt;/p&gt;
&lt;p&gt;Business analogy: Teach your app to use street addresses (DNS) even when it’s still living in your garage (Docker).&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Exact DNS Names for Kafka / ELK / MDM in Kubernetes&lt;br&gt;
These are the canonical, production‑safe names every pod should use.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Kafka&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka.default.svc.cluster.local:9092
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If using a dedicated namespace:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka.data.svc.cluster.local:9092
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Zookeeper&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;zookeeper.default.svc.cluster.local:2181
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Kafka Connect&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;connect.default.svc.cluster.local:8083
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Elasticsearch&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;elasticsearch.default.svc.cluster.local:9200
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If using a StatefulSet with headless service:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;elasticsearch-0.elasticsearch.default.svc.cluster.local:9200
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Kibana&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kibana.default.svc.cluster.local:5601
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;MDM ETL Jobs&lt;br&gt;
Jobs should reference Kafka and Elasticsearch via DNS:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka.default.svc.cluster.local:9092
elasticsearch.default.svc.cluster.local:9200
Bronze / Silver / Gold Storage
If using object storage:
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;minio.default.svc.cluster.local:9000
If using HDFS‑style:
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;namenode.default.svc.cluster.local:8020
2. How Docker Compose Can Simulate Kubernetes‑Style DNS
This is the trick that makes your local dev behave like a cluster.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Rule: Use service names, not localhost&lt;br&gt;
Docker Compose automatically creates an internal DNS zone where each service name resolves like a Kubernetes Service.&lt;/p&gt;
&lt;p&gt;Example docker‑compose.yml&lt;br&gt;
yaml&lt;/p&gt;
&lt;p&gt;services:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;  kafka:
    image: confluentinc/cp-kafka
    ports:
      - &quot;9092:9092&quot;

  zookeeper:
    image: confluentinc/cp-zookeeper
    ports:
      - &quot;2181:2181&quot;

  connect:
    image: confluentinc/cp-kafka-connect
    depends_on:
      - kafka
      - zookeeper
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Inside the network, these DNS names work:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka:9092
zookeeper:2181
connect:8083
elasticsearch:9200
kibana:5601
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Exactly like Kubernetes:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka.default.svc.cluster.local:9092
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;3-the-golden-rule-for-dev-ci-cd-kubernetes&quot;&gt;3. The Golden Rule for Dev → CI/CD → Kubernetes&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Never use localhost.&lt;br&gt;
Always use service names.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;docker-&quot;&gt;Docker:&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka:9092
elasticsearch:9200
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;kubernetes-&quot;&gt;Kubernetes:&lt;/h2&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka.default.svc.cluster.local:9092
elasticsearch.default.svc.cluster.local:9200
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Your code never changes — only the environment does.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;One‑line: Day zero.&lt;/p&gt;
&lt;p&gt;Two‑words: DNS first.&lt;/p&gt;
&lt;p&gt;Business analogy: If production uses street addresses, you don’t train your team on “my house, my room, my desk.”&lt;/p&gt;
&lt;p&gt;Direct answer (tight, mechanical, architect‑grade)&lt;br&gt;
Teams should switch to service‑style DNS from the very first local prototype, long before CI/CD or Kubernetes enter the picture.&lt;/p&gt;
&lt;p&gt;Because the moment you allow localhost:9092 into the code path, you’ve already baked in a failure mode:&lt;/p&gt;
&lt;p&gt;CI/CD → breaks&lt;/p&gt;
&lt;p&gt;Multi‑node cluster → breaks&lt;/p&gt;
&lt;p&gt;Sidecar networking → breaks&lt;/p&gt;
&lt;p&gt;Jobs/CronJobs → break&lt;/p&gt;
&lt;p&gt;Scaling → breaks&lt;/p&gt;
&lt;p&gt;Canary deploys → break&lt;/p&gt;
&lt;p&gt;Localhost is a lie in distributed systems.&lt;br&gt;
It only works on a laptop because Docker Compose simulates a fake single‑machine universe.&lt;/p&gt;
&lt;p&gt;The correct development sequence&lt;/p&gt;
&lt;h3 id=&quot;1-dev-environment-docker-&quot;&gt;1. Dev environment (Docker)&lt;/h3&gt;
&lt;p&gt;Use:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka:9092
elasticsearch:9200
zookeeper:2181
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Never:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;localhost:9092
127.0.0.1:9200
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;2-ci-cd&quot;&gt;2. CI/CD&lt;/h3&gt;
&lt;p&gt;Use the same names:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka:9092
elasticsearch:9200
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Your pipeline becomes cluster‑ready without changing a single line.&lt;/p&gt;
&lt;h3 id=&quot;3-kubernetes&quot;&gt;3. Kubernetes&lt;/h3&gt;
&lt;p&gt;DNS becomes:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-code&quot;&gt;kafka.svc.cluster.local:9092
elasticsearch.svc.cluster.local:9200
Same pattern, zero rewrites.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Why “DNS from day zero” is the only safe rule&lt;br&gt;
Eliminates environment drift&lt;/p&gt;
&lt;p&gt;Prevents pipeline failures&lt;/p&gt;
&lt;p&gt;Makes ETL jobs portable&lt;/p&gt;
&lt;p&gt;Avoids rewriting configs during migration&lt;/p&gt;
&lt;p&gt;Forces distributed‑system thinking early&lt;/p&gt;
&lt;p&gt;Protects MDM lineage and auditability&lt;/p&gt;
&lt;p&gt;If you wait until Kubernetes to fix localhost assumptions, you’re already in trouble — because your entire pipeline has been trained to believe in a topology that doesn’t exist in production.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/11450/dns-the-phonebook-of-the-internet</guid>
<pubDate>Wed, 11 Feb 2026 12:14:10 +0000</pubDate>
</item>
</channel>
</rss>