unable to chage type: ClusterIP to type: LoadBalancer for kube-dns in kubernetes

12/19/2018

When I run kubectl get svc -n kube-system it tells me:

NAME       TYPE        CLUSTER-IP   EXTERNAL-IP    PORT(S)        AGE
kube-dns   ClusterIP   xx.xx.xx.xx   <none>       53/UDP,53/TCP   13h

But when I try to kubectl edit svc/kube-dns -n kube-system:

error: services "kube-dns" is invalid

A copy of your changes has been stored to "/tmp/kubectl-edit-4p5gn.yaml"

error: Edit cancelled, no valid changes were saved.

I am unable to change it to a LoadBalancer...any ideas?

I also tried to create a new kube-dns also but I am unable to get an external-ip; it stays stuck in pending state.

kind: Service
metadata:
  name: kubedns-bkp
  namespace: kube-system
  labels:
    k8s-app: kube-dns
spec:
  type: LoadBalancer
  ports:
  - port: 53
    protocol: UDP
  selector:
    k8s-app: kube-dns

kubectl get svc -n kube-system reports:

NAME            TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
kubedns-bkp     LoadBalancer   xx.xx.xx.xx     <pending>     53:32115/UDP    5h

Note: I have created k8s cluster with ELB integration, for other services I successfully get external IPs.

-- Srinivasa Reddy
kube-dns
kubernetes

1 Answer

12/19/2018

So, two things here:

  1. As they advised you in the yaml validation errors that you chose not to share with us, one cannot change the type: of an existing Service; you have to create a new one, or delete the existing one and recreate it.
  2. However, I would strongly, strongly, strongly advise against deleting the kube-dns Service -- you are more than welcome to create a new Service of type: LoadBalancer and point it at the same selector: as kube-dns is using. That way anyone who wishes to use the load balanced service can, but the things in the cluster who depend on kube-dns being a ClusterIP with (likely) that existing xx.xx.xx.xx value can continue as before.
-- mdaniel
Source: StackOverflow