Kubernetes Service ExternalName

11/23/2019

I have some problems with Kubernetes ExternalName Service. I want to access server 'dummy.restapiexample.com' from the cluster . I created the following service:

apiVersion: v1
kind: Service
metadata:
   name: dummy-svc
spec:
    type: ExternalName
    externalName: dummy.restapiexample.com   
$ kubectl get svc
NAME         TYPE           CLUSTER-IP   EXTERNAL-IP                PORT(S)   AGE
dummy-svc    ExternalName   <none>       dummy.restapiexample.com   <none>    33m
kubernetes   ClusterIP      100.64.0.1   <none>                     443/TCP   6d19h

But when I try to access the service from a pod from the same namespace, I'm getting code HTTP 403.

$ curl -v http://dummy-svc/api/v1/employee/1
> GET /api/v1/employee/1 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: dummy-svc
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Content-Type: text/plain
< Date: Sat, 23 Nov 2019 14:21:05 GMT 
< Content-Length: 9
<

I can access the external server w/o any problem:

$ curl -v http://dummy.restapiexample.com/api/v1/employee/1> GET /api/v1/employee/1 HTTP/1.1 
> User-Agent: curl/7.35.0 
> Host: dummy.restapiexample.com
> Accept: */*                                                                                            
< HTTP/1.1 200 OK 
...
< Content-Length: 104
{"id":"1","employee_name":"56456464646","employee_salary":"2423","employee_age":"23","profile_image":""}

What is wrong with my code? Any hint will be highly appreciated.The cluster is runnung on AWS and installed with kops.

-- Stanislav Melnikov
kubernetes

1 Answer

11/23/2019

As pointed by Patrik W, the service works correctly. It routes requests to the remote server. Ping reaches the remote server:

$ ping dummy-svc

PING dummy.restapiexample.com (52.209.246.67) 56(84) bytes of data.
64 bytes from ec2-52-209-246-67.eu-west-1.compute.amazonaws.com (52.209.246.67): icmp_seq=1 ttl=62 time=1.29 ms

Code 403 received from the remote server because of different URLs.

@Patrik W: Thanks for the help.

-- Stanislav Melnikov
Source: StackOverflow