Solution for Kubernetes API Server access from within Pod without hostNetwork set to True
is Given Below:
I am using kopf to write a K8s operator. I have two containers: one is the operator container and the other is an application container exposing REST APIs. I have exposed the App container as a headless service with ClusterIP set to None.
If I set hostNetwork to True in the operator container and try to access the App container from within the operator container, I am not able to access it.
If I set hostNetwork to False in the operator container, I can ping the App container. However, I get this error:
[2021-08-02 07:32:19,088] kopf._core.engines.a [INFO ] Initial authentication has been initiated.
[2021-08-02 07:32:19,091] kopf.activities.auth [INFO ] Activity ‘login_via_client’ succeeded.
[2021-08-02 07:32:19,091] kopf._core.engines.a [INFO ] Initial authentication has finished.
[2021-08-02 07:34:29,427] kopf._core.reactor.r [ERROR ] Resource observer has failed: Cannot connect to host 10.96.0.1:443 ssl:default [Connect call failed (‘10.96.0.1’, 443)]
Any ideas as to how I can access both the API Server and the app container from my operator container?