AIOPs - Adding entries to Pod /etc/hosts
search cancel

AIOPs - Adding entries to Pod /etc/hosts

book

Article ID: 257031

calendar_today

Updated On:

Products

DX Operational Intelligence DX Application Performance Management

Issue/Introduction

Adding entries to a Pod's /etc/hosts file provides Pod-level override of hostname resolution when DNS and other options are not applicable, for example, in case of a network issue and fixing it is not immediate and adding the entries to the pod can used as a workaround

 

Environment

DX Platform 2x

Resolution

Table of Contents

In Kubernetes:

1) Edit a deployment

For example dxi-readserver:

kubectl edit deployment dxi-readserver -ndxi

NOTE: replace dxi with your correct namespace


2) Add the new hosts entries to the HostAliases property

For example:

hostAliases:
- ip: "192.0.2.1"
  hostnames:
  - "example.com"


3) Save the deployment -- a new pod will be created


4) Verify that /etc/host has been updated

Below an example:

kubectl get pods -ndxi | grep dxi-readserver
dxi-readserver-8559b6bff5-blhmp                        1/1     Running     0          4m37s

kubectl exec -ti -ndxi dxi-readserver-8559b6bff5-blhmp sh

more /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters

# Entries added by HostAliases.
192.0.2.1     example.com

In Openshift:

a) Edit the YAML of the Deployment

b) Add the New hosts entries to the HostAliases property as below for example:

hostAliases:
    - hostnames:
           - example.com
      ip: 192.0.2.1

 Example:

c) After the pod start, you can verify the new entry in the /etc/hosts file

Here is an example of a problem illustrating how updating the /etc/host in a deployment can be useful: Not able to login to the DX operational inteligence

Additional Information

https://knowledge.broadcom.com/external/article/190815/aiops-troubleshooting-common-issues-and.html 

https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/