This article describes how to assign host aliases to pods in kubernetes, is there anyway to do it for a deployment and not for a pod as such?
Any other suggestions to add host entries in kubernetes to provide a first line of host name resolution (before checking a server like 8.8.8.8) would be welcomed as an answer as well.
Yes this is possible. All you need to do is follow the same advice you were for a pod specification, but rather than applying it to a YAML file for pods, you apply it to a YAML file for a deployment. For example, if you are already running a deployment you can edit the current deployment by issuing the following command.
$ kubectl edit deployment DEPLOYMENT_NAME
This will allow you to access edit mode of the currently running deployment in YAML format.
You need to add the 'hostAliases' section in the deployments 'template: spec' field which allows you to configure the template for the pod/containers. So to demonstrate this visually, here is the YAML for a deployment I am running in my project that I can edit by running the command I mentioned above:
If I want to add 'hostAliases' to the pods within this deployment, I need to add this information to the pod template spec section as demonstrated below (notice it is in line with 'containers' (***important- it's worth noting that there are two 'spec' sections within my file- I don't want to add it to the first spec section, but rather the template spec section which defines the pod template):
hostAliases
is part of thePodSpec
, which is what you also find in Deployment underspec.template.spec
in your Deployment so you can easily use it in the same way in your Deployments Pod spec template as you do for Pod it self.