Unable to update kubernetes container /etc/hosts file using hostAliases

9/26/2019

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

Unable to make out what is stopping to updating hostAliases. And also, please suggest any alternative way to update /etc/hosts entries of a kubernetes container

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
-- SteveJbs
kubernetes

0 Answers