Not able to provide additional User-Data in instance groups through kops edit

2/8/2018

I'm trying to pass Additional user data to the nodes in k8s cluster deployed on AWS. To do that, I edited the IG 'nodes' and set the configuration to this...

apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
  creationTimestamp: 2018-02-07T13:25:13Z
  labels:
    kops.k8s.io/cluster: example.com
  name: nodes
spec:
  image: kope.io/k8s-1.7-debian-jessie-amd64-hvm-ebs-2018-01-14
  machineType: xx.xxx
  maxPrice: "xx.xx"
  maxSize: x
  minSize: y
  role: Node
  subnets:
  - xx-xxxx-xx
  additionalUserData:
  - name: myscript.sh
    type: text/x-shellscript
    content: |
      #!/bin/sh
      echo "xx.xxx.xxx.xx us-east-1a.fs-xxxxxx.efs.us-east-1.amazonaws.com" >> /etc/hosts
      echo "x.xx.xxx.xx us-east-1b.fs-xxxxx.efs.us-east-1.amazonaws.com" >> /etc/hosts
      echo "xxxx.xx.xxx.xxx us-east-1c.fs-xxxx.efs.us-east-1.amazonaws.com" >> /etc/hosts
      mkdir -p /opt/pvs
      echo "$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-xxxxx.efs.us-east-1.amazonaws.com:/ /opt/pvs nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0" >> /etc/fstab

But it doesn't work. No error logs are generated. Not sure how to even start debugging this issue. Everything works fine without the AdditionalUserData field.

-- Abhishek
kops
kubernetes

1 Answer

12/17/2019

Try it with

spec:
  additionalUserData:
  - content: |
      #!/bin/bash
      apt update
      apt install -y jq awscli
      mkdir -p /opt/pvs
      INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
    name: assign-eip.sh
    type: text/x-shellscript
-- Pablo Galeana Bailey
Source: StackOverflow