Skip to content

Instantly share code, notes, and snippets.

@guybrush
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guybrush/47bcd5f4e41a3be102b2 to your computer and use it in GitHub Desktop.
Save guybrush/47bcd5f4e41a3be102b2 to your computer and use it in GitHub Desktop.
kubernetes dns with a patched hack/local-up-cluster.sh
$ ~/dev/lib/kubernetes/cluster/kubectl.sh logs kube-dns-v8-rqehr kube2sky
I0713 05:43:34.025887 1 kube2sky.go:389] Etcd server found: http://127.0.0.1:4001
I0713 05:43:35.028313 1 kube2sky.go:455] Using http://127.0.0.1:8080 for kubernetes master
I0713 05:43:35.028353 1 kube2sky.go:456] Using kubernetes API v1
E0713 05:43:35.029755 1 reflector.go:136] Failed to list *api.Endpoints: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:35.030030 1 reflector.go:136] Failed to list *api.Service: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:36.031475 1 reflector.go:136] Failed to list *api.Service: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:36.032777 1 reflector.go:136] Failed to list *api.Endpoints: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:37.033914 1 reflector.go:136] Failed to list *api.Service: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:37.035569 1 reflector.go:136] Failed to list *api.Endpoints: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:38.035001 1 reflector.go:136] Failed to list *api.Service: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:38.036623 1 reflector.go:136] Failed to list *api.Endpoints: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:39.038011 1 reflector.go:136] Failed to list *api.Service: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:39.038250 1 reflector.go:136] Failed to list *api.Endpoints: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
E0713 05:43:40.039261 1 reflector.go:136] Failed to list *api.Service: couldn't get version/kind; json parse error: invalid character '<' looking for beginning of value
@guybrush
Copy link
Author

$ ~/dev/lib/kubernetes/cluster/kubectl.sh version
Client Version: version.Info{Major:"1", Minor:"0+", GitVersion:"v1.0.0-dirty", GitCommit:"cd821444dcf3e1e237b5f3579721440624c9c4fa", GitTreeState:"dirty"}
Server Version: version.Info{Major:"1", Minor:"0+", GitVersion:"v1.0.0-dirty", GitCommit:"cd821444dcf3e1e237b5f3579721440624c9c4fa", GitTreeState:"dirty"}

$ git diff hack/local-up-cluster.sh
diff --git a/hack/local-up-cluster.sh b/hack/local-up-cluster.sh
old mode 100755
new mode 100644
index b33a805..e2119c2
--- a/hack/local-up-cluster.sh
+++ b/hack/local-up-cluster.sh
@@ -242,6 +242,8 @@ function start_kubelet {
         --hostname_override="127.0.0.1" \
         --address="127.0.0.1" \
         --api_servers="${API_HOST}:${API_PORT}" \
+        --cluster_dns="10.0.0.10" \
+        --cluster_domain="cluster.local" \
         --port="$KUBELET_PORT" >"${KUBELET_LOG}" 2>&1 &
       KUBELET_PID=$!
     else


$ cat skydns-svc.yml
apiVersion: v1
kind: Service
metadata:
  name: kube-dns
  namespace: default
  labels:
    k8s-app: kube-dns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "KubeDNS"
spec:
  selector:
    k8s-app: kube-dns
  clusterIP:  "10.0.0.10"
  ports:
  - name: dns
    port: 53
    protocol: UDP
  - name: dns-tcp
    port: 53
    protocol: TCP


$ cat skydns-rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
  name: kube-dns-v8
  namespace: default
  labels:
    k8s-app: kube-dns
    version: v8
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 1
  selector:
    k8s-app: kube-dns
    version: v8
  template:
    metadata:
      labels:
        k8s-app: kube-dns
        version: v8
        kubernetes.io/cluster-service: "true"
    spec:
      containers:
      - name: etcd
        image: gcr.io/google_containers/etcd:2.0.9
        resources:
          limits:
            cpu: 100m
            memory: 50Mi
        command:
        - /usr/local/bin/etcd
        - -data-dir
        - /var/etcd/data
        - -listen-client-urls
        - http://127.0.0.1:2379,http://127.0.0.1:4001
        - -advertise-client-urls
        - http://127.0.0.1:2379,http://127.0.0.1:4001
        - -initial-cluster-token
        - skydns-etcd
        volumeMounts:
        - name: etcd-storage
          mountPath: /var/etcd/data
      - name: kube2sky
        image: gcr.io/google_containers/kube2sky:1.11
        resources:
          limits:
            cpu: 100m
            memory: 50Mi
        args:
        # command = "/kube2sky"
        - -kube_master_url=http://127.0.0.1:8080
        - -domain=cluster.local
      - name: skydns
        image: gcr.io/google_containers/skydns:2015-03-11-001
        resources:
          limits:
            cpu: 100m
            memory: 50Mi
        args:
        # command = "/skydns"
        - -machines=http://localhost:4001
        - -addr=0.0.0.0:53
        - -domain=cluster.local
        ports:
        - containerPort: 53
          name: dns
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
      - name: healthz
        image: gcr.io/google_containers/exechealthz:1.0
        resources:
          limits:
            cpu: 10m
            memory: 20Mi
        args:
        - -cmd=nslookup kubernetes.default.svc.cluster.local localhost >/dev/null
        - -port=8080
        ports:
        - containerPort: 8080
          protocol: TCP
      volumes:
      - name: etcd-storage
        emptyDir: {}
      dnsPolicy: Default  # Don't use cluster DNS.

@guybrush
Copy link
Author

i got it working, the problem was

  • kube2sky argument is -kube_master_url=http://127.0.0.1:8080, which doesnt work since 127.0.0.1 is the pod
  • my host has ip-addr: 10.0.0.161 which overlaps with the service-ip-range 10.0.0.0/24

i solved it by

  • putting an extra kube-proxy container into the skydns-rc (see examples/kubectl-container)
  • setting the clusterIp in skydns-svc and kubelet-argument --cluster_dns to 10.100.0.10
  • setting the service-ip-range to 10.100.0.0/24

note: first i tried to set --insecure_port=8080 and --insecure_bind_address=0.0.0.0 on the apiserver, instead of putting the kube-proxy container into the skydns-rc, which also works but exposes the apiserver publicly (which is suboptimal)

@prakash-gemini
Copy link

I have setup skydns in kubernetes 1.1 with flannel on centos 7. i am facing same issue. i deployed my cluster-ip with 10.254.0.100 ip address my portal not routable ip is 10.254.0.0/16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment