How to update worker nodes /etc/hosts file in GKE

1/4/2019

I have created a GKE cluster using terraform script. I have a scenario where the /etc/hosts file has to be updated. Is it possible to update the host file on worker nodes during K8 cluster creation using terraform?

-- Sunil Gajula
google-cloud-platform
google-compute-engine
google-kubernetes-engine
terraform

1 Answer

1/4/2019

With terraform it's not possible to access the directory, You can use a DeamonSet with Security Context as privileged see below:

kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
  name: ssd-startup-script
  labels:
    app: ssd-startup-script
spec:
  template:
    metadata:
      labels:
        app: ssd-startup-script
    spec:
      hostPID: true
      containers:
      - name: ssd-startup-script
        image: gcr.io/google-containers/startup-script:v1
        imagePullPolicy: Always
        securityContext:
          privileged: true
        env:
        - name: STARTUP_SCRIPT
          value: |
            #!/bin/bash
            <YOUR COMMAND LINE>
            <YOUR COMMAND LINE>
            <YOUR COMMAND LINE>
            echo Done

you need to run the kubectl apply -f <demonset yaml file>

-- Alioua
Source: StackOverflow