kubernetes transfer Physical IP to dubbo

3/9/2017

I want to transfer Physical IP to dubbo pod by yaml,but the parameter is Fixed value.For example: dubbo.yaml

spec:
  replicas: 2
  ...
    env:
            - name:  PhysicalIP
              value: 192.168.1.1

In pod before start dubbo,i can replay container ip,for example:

echo "replay /etc/hosts"
cp /etc/hosts /etc/hosts.tmp
sed -i "s/.*$(hostname)/${PhysicalIP}   $(hostname)/" /etc/hosts.tmp
cat /etc/hosts.tmp > /etc/hosts

There is an question,when pod deploy to host 192.168.1.1 and host 192.168.1.2,the host 192.168.1.2's pod environment variable ${PhysicalIP} value is 192.168.1.1,I want to ${PhysicalIP} is 192.168.1.2 in host 192.168.1.2,Is there any way?

-- eric
kubernetes

1 Answer

3/28/2017

You should be able to get information about the pod through Environment Variables or using a DownwardAPIVolumeFile.

  • Using environment variables:

    You should add to your yaml something like this:

    env:
      - name: MY_NODE_NAME
        valueFrom:
          fieldRef:
            fieldPath: spec.nodeName

As far as I know, the name of the node is, right now, the best approach to what you need that you can get from inside the container.

  • Using a DownwardAPIVolumeFile:

    You should add to your yaml something like this:

    volumes:
      - name: podinfo
        downwardAPI:
          items:
            - path: "nodename"
              fieldRef:
                fieldPath: spec.nodeName

This way you will have the information of the node name stored in /etc/nodename

The issue #24657 and the pull #42717, on the kubernetes github are related to this. (Sorry, I need more reputation here to be able to post more links!).

As you can see there, access to the node IP through the downwardAPI should be available soon (using status.hostIP, probably).

-- aespejel
Source: StackOverflow