kbe icon indicating copy to clipboard operation
kbe copied to clipboard

Inconsistent domain names for service discovery

Open marekjelen opened this issue 7 years ago • 0 comments

Minishift and Kubernetes default to different namespaces, myproject and default respectively and that makes the service discovery chapter non-consistent across environments.

The command

kubectl exec jumpod -c shell -i -t -- ping thesvc.default.svc.cluster.local

will work on Kubernetes cluster, but not in OpenShift as default is restricted and in most installation including minishift the user will no be allowed to use the namespace.

In case the tutorials want to as well target on-lin service users, it should not rely on hard-coded name, as the namespace names has to be unique across users, it would only work for one user.

There are some possible ways how to solve this.

The content could be tweaked so that the user is well aware of the namespaces. But that would require creation of separate paths for Kubernetes and OpenShift, as they have different ways to create them.

Other way is to teach the user some way how to learn the namepace, (is there actually some simple command on kubectl level what would return the current namespace ?) e.g.

kubectl get pod jumpod -o jsonpath="{.metadata.namespace}"

and then let the user substitute the name in the command

kubectl exec jumpod -c shell -i -t -- getent hosts thesvc.$YOUR_NAMESPACE.svc.cluster.local

Another one is provide some command that would figure out the FQDN on the server at runtime, like this dirty hack

kubectl exec jumpod -c shell -i -t -- /bin/bash -c 'NAME=`cat /etc/resolv.conf | grep -o "search [^ ]*"`; NAME=($NAME); NAME=${NAME[1]}; getent hosts thesvc.$NAME'

marekjelen avatar Jul 06 '17 16:07 marekjelen