2

I have this bootstrap script for my EKS node-group launch template and I added in some commands to try to install Apache. I tried a few variations and none would install the service. I'm able to do it manually if I ssh into my nodes, but haven't been able to accomplish it with my script

bootstrap.sh

Variation #1

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
set -ex
/etc/eks/bootstrap.sh ${cluster_name} \
  --container-runtime containerd

sudo su
yum update -y
yum install httpd -y
service httpd start

--==MYBOUNDARY==--

Variation #2

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
sudo su
yum update -y
yum install httpd -y
service httpd start
set -ex
/etc/eks/bootstrap.sh ${cluster_name} \
  --container-runtime containerd

--==MYBOUNDARY==--

Variation #3

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
set -ex
/etc/eks/bootstrap.sh ${cluster_name} \
  --container-runtime containerd

--==MYBOUNDARY==--

#!/bin/bash
sudo su
yum update -y
yum install httpd -y
service httpd start

I also tried with and without the sudo su and none of those worked either. Just seems like the commands aren't running at all

  • I would install the apache at Dockerfile level. That's why docker exist – JRichardsz Jul 09 '22 at 14:23
  • @JRichardsz Prior to this, I always used EKS cli so I would create my K8s files and a docker image as well. I haven't had to specify a Docker image when deploying my cluster and node group via Terraform, if I created a docker image with apache, how do I get my nodes to deploy with it? Do I need to change my runtime from containerd to Docker as well? –  Jul 10 '22 at 00:18
  • Which OS that your node group uses? AL2 or ? – Binh Nguyen Jul 11 '22 at 17:36
  • Can you share the system log of one of these nodes? (Actions > Monitor and troubleshoot > Get system log) – ericfossas Jul 13 '22 at 21:33

1 Answers1

0

I simply used the below code in the userdata of the launch template & it was never a problem.

#!/bin/bash
/etc/eks/bootstrap.sh your_cluster_name_here
sudo adduser ssm-user
sudo usermod -a -G docker ssm-user
sudo adduser uua
sudo usermod -g wheel uua
sudo sed -i  's/^# %wheel/%wheel/' /etc/sudoers
sudo adduser uub

It's Under EC2 > Launch Templates > (your launch template) > Details > Advanced Details

Screenshot Reference AWS EC2 Launch Template User Data

iArc13
  • 162
  • 8
  • Were you able to get it working with EKS? I have a script to install Apache that works fine for an EC2 launch template, but for some reason when I include it in my launch template for my EKS self managed nodes, it doesn't work at all. My current script in my post is used to join my nodes to the cluster and that part works fine, but when I also add the commands to install Apache, it doesn't get installed. I can't figure it out for the life of me –  Jul 06 '22 at 08:11
  • @heritagesquad Yes, I have used it in EKS itself. Correct me if I'm wrong - the script is executed when the nodes are launched, but you mentioned you're using self managed nodes. Does that mean your nodes are already launched ? If that's the case, then I guess the script would not work as it is executed when nodes are "launched = created". – iArc13 Jul 09 '22 at 23:02
  • @heritagesquad I have been using spot instances. So, when a new instance is launched, the script is run on that instance to initialise the ssm agent (used to login via SSH to ec2 without keys). PS: I am using spot to save money :) – iArc13 Jul 09 '22 at 23:05