Kops utilizes cloud-init to initialize and setup a host at boot time. You may have a use-case where specific software should be configured on Bastion server when kops is used to create kubernetes cluster. Items like kops, kubectl, jq, awscli and exporting kubecfg can be installed during the Bastion box creation. Additional user-data can be passed to the host provisioning by setting the additionalUserData
field.
You can sue the sample yaml template for bastion server created by kops-
apiVersion: kops.k8s.io/v1alpha2 kind: InstanceGroup metadata: creationTimestamp: null labels: kops.k8s.io/cluster: test.demo.local name: bastions spec: associatePublicIp: true additionalUserData: - name: myscript.sh type: text/x-shellscript content: | #!/bin/sh HOME="/home/admin" cd $HOME sudo apt-get -y update sudo apt-get -y install jq awscli sudo apt-get -y install unzip KOPS_FLAVOR="kops-linux-amd64" KOPS_VERSION=$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4) KOPS_URL="https://github.com/kubernetes/kops/releases/download/${KOPS_VERSION}/${KOPS_FLAVOR}" curl -sLO ${KOPS_URL} chmod +x ${KOPS_FLAVOR} sudo mv kops-linux-amd64 /usr/local/bin/kops KUBECTL_VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) KUBECTL_URL="https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl" curl -sLO ${KUBECTL_URL} chmod +x kubectl sudo mv kubectl /usr/local/bin/kubectl CLUSTER_NAME="test.demo.local" STATE="s3://test-kops-teststore" sudo kops export kubecfg --name ${CLUSTER_NAME} --state ${STATE} sleep 10 cp -r /root/.kube /home/admin/.kube sudo chown -R admin: /home/admin/.kube image: kope.io/k8s-1.15-debian-stretch-amd64-hvm-ebs-2020-01-17 machineType: t2.small maxSize: 1 minSize: 1 nodeLabels: kops.k8s.io/instancegroup: bastions role: Bastion subnets: - utility.ap-southeast-2a.test.demo.local ---
For more details check this article: How to create kubernetes cluster using kops cluster template.
You can do lot more of scripting in additionalUserData
field. kops will keep running the script until everything mentioned in it is executed.