<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Configure custom DNS server and host aliases to Kubernetes Pods - Kubernetes and Containers				            </title>
            <link>https://www.virtualizationhowto.com/community/kubernetes-and-containers/configure-custom-dns-server-and-host-aliases-to-kubernetes-pods/</link>
            <description>Virtualization Howto Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Sat, 08 Aug 2026 00:45:15 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Configure custom DNS server and host aliases to Kubernetes Pods</title>
                        <link>https://www.virtualizationhowto.com/community/kubernetes-and-containers/configure-custom-dns-server-and-host-aliases-to-kubernetes-pods/#post-1055</link>
                        <pubDate>Thu, 21 Nov 2024 21:20:45 +0000</pubDate>
                        <description><![CDATA[You may have a need to configure a custom DNS server setting for your Kubernetes pods. Or, you may need to add a host alias in a specific pod just to do some custom name resolution. How do y...]]></description>
                        <content:encoded><![CDATA[<p>You may have a need to configure a custom DNS server setting for your Kubernetes pods. Or, you may need to add a host alias in a specific pod just to do some custom name resolution. How do you do this? Well, as it turns out there is custom YAML code we can apply to add these values for our pods. </p>
<p>For setting a specific DNS server for your pod, you can use the following:</p>
<pre contenteditable="false">kubectl patch deployment server -n myapp \
  --type=json \
  -p='[
    {
      "op": "add",
      "path": "/spec/template/spec/dnsPolicy",
      "value": "None"
    },
    {
      "op": "add",
      "path": "/spec/template/spec/dnsConfig",
      "value": {
        "nameservers": , 
        "searches": 
      }
    }
  ]'
</pre>
<p>For setting specific host aliases, you can use the following:</p>
<pre contenteditable="false">kubectl patch deployment server -n myapp \
  --type=json \
  -p='[
    {
      "op": "add",
      "path": "/spec/template/spec/hostAliases",
      "value": [
        {
          "ip": "&lt;ip of server&gt;",
          "hostnames": 
        }
      ]
    }
  ]'
</pre>
<p>You can check and see if your deployment was updated correctly:</p>
<pre contenteditable="false">kubectl get deployment server -n myapp -o yaml | grep -A 5 dnsConfig
kubectl get deployment server -n myapp -o yaml | grep -A 5 hostAliases
</pre>
<p>If you need to roll back your DNS changes, you can use this:</p>
<pre contenteditable="false">kubectl patch deploymentserver -n myapp \
  --type=json \
  -p=''
</pre>
<p> </p>
<p>Well, there you have it. A simple way to add a custom DNS server configuration or host aliases to specific pods. Pretty cool</p>]]></content:encoded>
						                            <category domain="https://www.virtualizationhowto.com/community/kubernetes-and-containers/">Kubernetes and Containers</category>                        <dc:creator>Brandon Lee</dc:creator>
                        <guid isPermaLink="true">https://www.virtualizationhowto.com/community/kubernetes-and-containers/configure-custom-dns-server-and-host-aliases-to-kubernetes-pods/#post-1055</guid>
                    </item>
							        </channel>
        </rss>
		