How to update /etc/services for k8s pod / Docker container

6/29/2020

I need to update my /etc/services file with adding some extra line to it. But I could not find any straight answers to this. In k8s there is an option to add hostAliases for /etc/hosts by editing deployment object but no options to update /etc/services

As an option, I could mount my own file but this is a too brutal way to do this IMO.

Thanks in advance!

-- cudouny
docker
kubernetes

1 Answer

6/30/2020

Replacing your /etc/services with a mounted ConfigMap would have the merit of being able to make updates while your Pods are running.

If you don't want to use that technique, you can use a PostStart Lifecycle Hook to add lines whenever your Pods start or restart:

lifecycle:
  postStart:
    exec:
      command: ["/bin/sh", "-c", "echo '[new-line]' >> /etc/services"]	
-- Fritz Duchardt
Source: StackOverflow