Setup SkyDNS on a Kubernetes Cluster

  Uncategorized

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

APP_SERVICE_HOST=<app host>
APP_SERVICE_PORT=<app port>

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):

redis-master.default.kubernetes.local

Requirements

  • Functional Kubernetes cluster
  • Kubernetes container subnet: 10.254.0.0/16
  • Kubernetes DNS IP address: 10.254.0.10
  • 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
labels:
  k8s-app: skydns
desiredState:
  replicas: 1
  replicaSelector:
    k8s-app: skydns
  podTemplate:
    labels:
      k8s-app: skydns
    desiredState:
      manifest:
        version: v1beta2
        id: skydns
        dnsPolicy: "Default"
        containers:
          - name: etcd
            image: quay.io/coreos/etcd:latest
            command: [
              "/etcd",
              "-bind-addr=127.0.0.1",
              "-peer-bind-addr=127.0.0.1",
            ]
          - name: kube2sky
            image: kubernetes/kube2sky:1.0
            command: [
              # entrypoint = \"/kube2sky\",
              "-domain=kubernetes.local",
            ]
          - name: skydns
            image: kubernetes/skydns:2014-12-23-001
            command: [
              # entrypoint = \"/skydns\",
              "-machines=http://localhost:4001",
              "-addr=0.0.0.0:53",
              "-domain=kubernetes.local.",
            ]
            ports:
              - 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
portalIP: 10.254.0.10
containerPort: 53
labels:
  k8s-app: skydns
selector:
  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=10.254.0.10
  • --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=10.254.0.10 --cluster_domain=kubernetes.local"

Kubelet on Ubuntu

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

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

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

Views: 6

LEAVE A COMMENT

What is the capital of Egypt? ( Cairo )