Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
How to add custom host entries to kubernetes Pods?

My application communicates to some services via hostnames. When running my application as a docker container i used to add hostnames to the /etc/hosts of the hostmachine and run the container using --net=host.

Now I'm running my containers in kubernetes cluster. I would like to know how can i add the /etc/hosts entries to the pod via yaml.

I'm using kubernetes v1.5.3.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

From k8s 1.7 you can add hostAliases. Example from the docs:

apiVersion: v1
kind: Pod
metadata:
  name: hostaliases-pod
spec:
  restartPolicy: Never
  hostAliases:
  - ip: "127.0.0.1"
    hostnames:
    - "foo.local"
    - "bar.local"
  - ip: "10.1.2.3"
    hostnames:
    - "foo.remote"
    - "bar.remote"
over 4 years ago · Santiago Trujillo Report

0

Host files are going to give you problems, but if you really need to, you could use a configmap.

Add a configmap like so

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-app-hosts-file-configmap
data:
  hosts: |-
    192.168.0.1 gateway
    127.0.0.1 localhost

Then mount that inside your pod, like so:

  volumeMounts:
    - name: my-app-hosts-file
      mountPath: /etc/
volumes:
  - name: my-app-hosts-file
    configMap:
    name: my-app-hosts-file-configmap
over 4 years ago · Santiago Trujillo Report

0

This works and also looks simpler:

kind: Service
apiVersion: v1 
metadata:
    name: {HOST_NAME} 
    spec:
      ports:
        - protocol: TCP
          port: {PORT}
          targetPort: {PORT}
      type: ExternalName
      externalName: {EXTERNAL_IP}

Now you can use the HOST_NAME from the pod directly to access the external machine.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!