Connecting with Elixir app hosted in Kubernetes Pod

1/7/2019

I've been given the following Kubernetes pod and headless service YAML configuration file:

apiVersion: v1
kind: Service
metadata:
  name: elixir
spec:
  clusterIP: None
  selector:
    app: elixir
  ports:
  - port: 4369

apiVersion: v1
kind: Pod
metadata:
  name: e1
  labels:
    app: elixir
spec:
  hostname: e1
  subdomain: elixir
  dnsPolicy: ClusterFirst
  restartPolicy: Never
  containers:
  - name: elixir
    image: bitwalker/alpine-elixir
    env:
    - name: MYDNSDOMAIN
      value: elixir.default.svc.cluster.local
    - name: MYPODNAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
    - name: MYPODIP
      valueFrom:
        fieldRef:
          fieldPath: status.podIP
    command: [ "sh" ]
    args: [  "/programa/run_elixir.sh", "$(MYPODNAME).$(MYDNSDOMAIN)"]
    ports:
    - containerPort: 4369
    volumeMounts:
    - name: programa-volume
      mountPath: /programa
  volumes:
  - name: programa-volume
    configMap:
      name: cm-elixir
      items:
      - key: run_elixir.sh
        path: run_elixir.sh
        mode: 0777
      - key: prueba.exs
        path: prueba.exs
        mode: 0777 

It is supossed to start a simple elixir program inside a pod in my cluster.run_elixir.sh is a shell script that launches the program setting as node name the pod name and as host, the DNS domain. Both the service and the pod start up successfully (I can see the program output if I enter kubectl logs e1).

However, I'm not able to connect to the elixir node from outside of the cluster (actually I can't even do it from inside): in order to do that, I use Node.connect(:"e@e1.elixir.default.svc.cluster.local"). Should that work? Am I supossed to do something else, like maybe adding the cluster DNS server to my local machine DNS server list?

Any help will be appreciated.

-- pitazzo
elixir
kubernetes

0 Answers