0

I am trying to update k8s container /etc/hosts file through hostAliases with Deployment kind, however this is not updating /etc/hosts but deployment is successful.

Here is the deployment.yml file I am using, appreciate your help

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-services
  namespace: dev
  labels:
    app: test-services
spec:
  replicas: 1
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: test-services
  template:
    metadata:
      labels:
        app: test-services
    spec:   
      containers:
      - name: test-services
        image: test-services:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 5
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 60
          periodSeconds: 5
        env:
        - name: JAVA_OPTS
          value: "-Dspring.profiles.active=dev"
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: db-credentials
              key: username
        - name: DB_PASS
          valueFrom:
            secretKeyRef:
              name: db-credentials
              key: password
      restartPolicy: Always
      hostAliases:
      - ip: "127.0.0.1"
        hostnames:
        - "foo.local"
        - "bar.local"
      - ip: "10.1.2.3"
        hostnames:
        - "foo.remote"
        - "bar.remote" 
      imagePullSecrets:  
      - name: registry-secret

here is the output of hosts file:

# 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
10.45.3.28      test-services-7799d8d9-vrwd2
SteveJbs
  • 1
  • 2
  • Could you post the output of /etc/hosts on the pod in question? Per https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/, your hostAliases section should achieve what you are hoping - what are the symptoms of the issue you are trying to solve? – iwaseatenbyagrue Sep 26 '19 at 07:26
  • @iwaseatenbyagrue here is the output of hosts file: ``` # 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 10.45.3.28 test-services-7799d8d9-vrwd2 ```
    I have a FQDN (ex: iibserver.abc.com)which is not resolved by my cloud cluster, to overcome that I explicitly wanted to update the hosts file to point to the IP address (ex: 10.1.10.1)
    – SteveJbs Sep 26 '19 at 13:22
  • How did you want to upgrade it? `patch`, `edit`, bluegreen deployment? I am not able to reproduce your issue. – PjoterS Oct 02 '19 at 14:26

0 Answers0