0

We're using kustomize with kubernetes on our project.

I'm trying to implement access to external service using IP as mentioned in this link

https://medium.com/@ManagedKube/kubernetes-access-external-services-e4fd643e5097

Here's my service

---
kind: Service
apiVersion: v1
metadata:
  name: pgsql
spec:
  ports:
   - protocol: TCP
     port: 5432
     targetPort: 5432
     name: "pg"
  selector: {}
---
apiVersion: v1
kind: Endpoints
metadata:
  name: pgsql
subsets:
  - addresses:
      - ip: 1.1.1.1
    ports:
      - port: 5432
        name : "pg"

When I apply with kubectl command (kubectl apply -k ...) I have a warning

Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply

However, this warning does not avoid endpoints and service creation.

kubectl get endpoints

NAME                ENDPOINTS           AGE
pgsql               172.12.xx.yy:5432   3m27s

Unfortunately, the ip address is different from the one I put in my yml (1.1.1.1)

If I apply a second time

kubectl apply -k ...

kubectl get endpoints

NAME                ENDPOINTS           AGE
pgsql               1.1.1.1:5432   10s

I do not have the warning above anymore.

The endpoint is the one expected.

I expect endpoint address to be the exact one (1.1.1.1:5432) from the first apply.

Any suggestions?

Thanks

  • output of kubectl version? are you sure you did not have these resources created already by some other means before applying first time? – Arghya Sadhu Jul 01 '20 at 15:06
  • @Arghya Sadhu, I deleted all my resources before applying the first time. i user kubectl server 1.16.4 kubectl client 1.17.2 – user8794331 Jul 01 '20 at 16:36
  • Can you please add the `Kustomize` files to create your services to your question for others to check if they observe the same behavior? – Dawid Kruk Jul 02 '20 at 10:35

1 Answers1

0

It probably comes from the empty selector. Could you try to remove it completely? This is supposed to work only if your service doesn't have any selector

ITChap
  • 4,057
  • 1
  • 21
  • 46