Setup SkyDNS on a Kubernetes Cluster


By default, the containers allows for service discovery through the use of dynamic environment variables that are similar to the Docker syntax. For example:


Kubernetes also provides support for a cluster DNS add-on. When this add-on is enabled, Kubernetes Services will automatically create associated DNS records that are resolvable within the containers.

The format of the DNS record is service_name.namespace.cluster_domain. Based on this tutorial, for example, a redis-master Service may use the following domain (assuming the default namespace is being used):



  • Functional Kubernetes cluster
  • Kubernetes container subnet:
  • Kubernetes DNS IP address:
  • Kubernetes domain name: kubernetes.local

NoteIf you chose another container subnet in your existing Kubernetes cluster, then the skydns PortalIP must reside in that subnet and the Kubelet startup parameter --cluster_dns must match that IP address.

Create Replication Controller Manifest

The Replication Controller manifest will describe the state of the containers within the Pod as well as the number of replicas. The skydns Pod will consist of three containers:

  • etcd โ€“ Stores the SkyDNS configuration and DNS records.
  • skydns โ€“ The DNS server responding to requests.
  • kube2sky โ€“ A bridge between Kubernetes and SkyDNS.

Create a file called skydns-rc.yaml and paste in the following YAML text:

kind: ReplicationController
apiVersion: v1beta1
id: skydns
namespace: default
  k8s-app: skydns
  replicas: 1
    k8s-app: skydns
      k8s-app: skydns
        version: v1beta2
        id: skydns
        dnsPolicy: "Default"
          - name: etcd
            command: [
          - name: kube2sky
            image: kubernetes/kube2sky:1.0
            command: [
              # entrypoint = \"/kube2sky\",
          - name: skydns
            image: kubernetes/skydns:2014-12-23-001
            command: [
              # entrypoint = \"/skydns\",
              - name: dns
                containerPort: 53
                protocol: UDP

Create Service Manifest

The Service manifest will expose the DNS service IP address and port to other containers within the cluster.

Create a new service file called skydns-svc.yaml and paste in the following YAML text.

kind: Service
apiVersion: v1beta1
id: skydns
namespace: default
protocol: UDP
port: 53
containerPort: 53
  k8s-app: skydns
  k8s-app: skydns

Load the Manifests

The manifest files are now ready to be loaded into Kubernetes using the kubectl command.

kubectl create -f ./skydns-rc.yaml
kubectl create -f ./skydns-svc.yaml

The kubectl command can also be used to confirm the state of the new skydns Replication Controller, Pod, and Service.

kubectl get rc
kubectl get pods
kubectl get service

Configure the Kubelet Services

Cluster DNS must now be enabled on all the container nodes. This is done by adding two startup parameters to the Kubelet service. Open the kubelet configuration file on each host and add the following two parameters:

  • --cluster_dns=
  • --cluster_domain=kubernetes.local

The location of the kubelet configuration file may vary along with the parameter syntax depending on the Linux distribution. For example:

Kubelet on CentOS 7

The /etc/kubernetes/kubelet file should contain the following:

KUBELET_ARGS="--cluster_dns= --cluster_domain=kubernetes.local"

Kubelet on Ubuntu

The /etc/default/kubelet may appear similar to this example:

KUBELET_OPTS="--address= \
--port=10250 \
--hostname_override=kube-minion \
--etcd_servers=http://kube-master:4001 \
--enable_server=true \
--cluster_dns= \
--cluster_domain=kubernetes.local \

Restart the Kubelet

Finally, restart the Kubelet to enable cluster DNS. To restart the service on CentOS:

systemctl restart kubelet

And to restart the service on Ubuntu:

service docker restart

Visits: 4


What is the capital of Egypt? ( Cairo )