Random characters when describing kubernetes namespaces

4/26/2018

I'm trying to connect my Kubernetes deployments together via DNS.

I have a Java (Spring Boot) deployment and a javascript (node.js) deployment, both exposed via a default ClusterIP Service. I need websocket and REST communication between both services.

I've read that I should use DNS so that these two services can talk to each other, but I'm having trouble trying to determine what those DNS's are.

For example,

kubectl get pods --all-namespaces

gives me this:

NAMESPACE NAME default javascript-deployment-65869b7db4-mxfrb default java-deployment-54bfc87fd6-z8wml

  1. What do I need to specify in my Service config to stop these random suffixes being applied?
  2. How do I then determine what my DNS names need to be with a similar form of my-svc.my-namespace.svc.cluster.local?
-- wild_nothing
dns
kubernetes
kubernetes-deployment
kubernetes-service
namespaces

2 Answers

4/27/2018

I fixed it using the Service metadata name and port.

For example, this is my service definition:

apiVersion: v1
kind: Service
metadata:
  name: my-big-deployment
spec:
  ports:
  - port: 8000
    protocol: TCP
    targetPort: 8000
selector:
  app: my-service

From my applications in the cluster I can now access this service via the following environment variables:

MY_BIG_DEPLOYMENT_SERVICE_HOST
MY_BIG_DEPLOYMENT_SERVICE_PORT
-- wild_nothing
Source: StackOverflow

4/26/2018

About your questions:

1- Kubernetes doesn't recommend to avoid creating the names because basically, it ensures that the pods are unique and also, the first part of the hash it groups all the pods with the same replica-controller.

So just as advice, don't touch it. https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#pod-template-hash-label

2- kubectl get services -o wide will provide you in which port is your app listening. You just need to use the cluster ip + port like CLUSTER_IP:PORT to be able to reach your service.

-- Idir Ouhab Meskine
Source: StackOverflow