Home > database >  How to access ExternalName service in kubernetes using minikube?
How to access ExternalName service in kubernetes using minikube?

Time:12-15

I understand that a service of type ExternalName will point to a specified deployment that is not exposed externally using the specified external name as the DNS name. I am using minikube in my local machine with docker drive. I created a deployment using a custom image. When I created a service with default type (Cluster IP) and Load Balancer for the specific deployment I was able to access it after port forwarding to the local ip address. This was possible for service type ExternalName also but accessible using the ip address and not the specified external name.

According to my understanding service of type ExternalName should be accessed when using the specified external name. But I wasn't able to do it. Can anyone say how to access an external name service and whether my understanding is correct?

This is the externalName.yaml file I used.

apiVersion: v1
kind: Service
metadata:
  name: k8s-hello-test
spec:
  selector:
    app: k8s-yaml-hello
  ports:
  - port: 3000
    targetPort: 3000
  type: ExternalName
  externalName: k8s-hello-test.com

After port forwarding using kubectl port-forward service/k8s-hello-test 3000:3000 particular deployment was accessible using http://127.0.0.1:300 But even after adding it to etc/hosts file, cannot be accessed using http://k8s-hello-test.com

CodePudding user response:

According to my understanding service of type ExternalName should be accessed when using the specified external name. But I wasn't able to do it. Can anyone say how to access it using its external name?

You are wrong, external service is for making external connections. Suppose if you are using the third party Geolocation API like https://findmeip.com you can leverage the External Name service.

An ExternalName Service is a special case of Service that does not have selectors and uses DNS names instead. For more information, see the ExternalName section later in this document.

For example

apiVersion: v1
kind: Service
metadata:
  name: geolocation-service
spec:
  type: ExternalName
  externalName: api.findmeip.com

So your application can connect to geolocation-service, which which forwards requests to the external DNS mentioned in the service.

As ExternalName service does not have selectors you can not use the port-forwarding as it connects to POD and forwards the request.

Read more at : https://kubernetes.io/docs/concepts/services-networking/service/#externalname

  • Related