Skip to content

Commit

Permalink
add slight more work to figure out the hostnames
Browse files Browse the repository at this point in the history
It is still a bit of a hack. Ideally we can add identifiable hostnames
to the /etc/hosts of each. I am having trouble debugging because
there seems to be some delay in the info being available with the aws
Python sdk, and then I am not able to always shell into instances with
my PEM

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Sep 7, 2023
1 parent f5a131d commit d8e9a3e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,7 @@ We will be developing this further to run usernetes. Next steps are:
2. Install rootless docker (by the user on startup)
3. Individual commands for control plane / workers to setup usernetes

TBA! You can look at the startup

script logs like this if you need to debug.

```bash
$ cat /var/log/cloud-init-output.log
```

That's it. Enjoy!
Follow the commands in the examples basic README.md for next steps.

## License

Expand Down
29 changes: 29 additions & 0 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,32 @@ export TF_VAR_aws_secret=$AWS_SECRET_ACCESS_KEY
export TF_VAR_aws_key=$AWS_ACCESS_KEY_ID
export TF_VAR_aws_session=$AWS_SESSION_TOKEN
```

### Usage

Change your key in the [main.tf](main.tf) and then bring up the cluster:

```bash
make
```
You'll need to get instance connection strings from the AWS console. And then typically
you need to login as the ubuntu user, and with your pem:

```bash
$ ssh -i "key.pem" -o "IdentitiesOnly=yes" ubuntu@ec2-44-198-52-73.compute-1.amazonaws.com
```

You can look at the startup script logs like this if you need to debug.

```bash
$ cat /var/log/cloud-init-output.log
```

Next steps are:

1. Get hostnames / addresses into /etc/hosts
2. Install rootless docker (by the user on startup)
3. Individual commands for control plane / workers to setup usernetes

I started on step 1, but am having trouble just ssh-ing into instances (sometimes I always get permission denied, and then the hostname does not
take). If/when we get that working, we will want to mimic the steps [here](https://github.com/converged-computing/usernetes-terraform-gcp/tree/main/examples/basic). To make things easier we likely want to add logic to the above to define a hostname for the control plane, etc. that is written to each. The main difference in design is that GCP gives predictable hostnames, and aws does not.
12 changes: 6 additions & 6 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# VARIABLES # for you to edit!

locals {
name = "usernetes"
pwd = basename(path.cwd)
region = "us-east-1"
name = "usernetes"
pwd = basename(path.cwd)
region = "us-east-1"
# Output AMI from build-images
ami = "ami-0a71a4436084046bc"
instance_type = "m4.large"
vpc_cidr = "10.0.0.0/16"
key_name = "<Your-key-here>"
key_name = "<My-Key-Id>"

# Must be larger than ami
volume_size = 30
Expand Down Expand Up @@ -45,8 +45,8 @@ terraform {
# Read in a shared script to init / finalize the setup
data "template_file" "startup_script" {
template = templatefile("../scripts/setup.sh", {
selector_name = local.name,
desired_size = local.desired_size
selector_name = local.name,
desired_size = local.desired_size
})
}

Expand Down
20 changes: 6 additions & 14 deletions examples/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@ done
found_count=$(aws ec2 describe-instances --region us-east-1 --filters "Name=tag:selector,Values=${selector_name}-selector" | jq .Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddress | wc -l)
echo "Desired count $found_count is reached"

# Update the config files with our hosts - we need the ones from hostname
hosts=$(aws ec2 describe-instances --region us-east-1 --filters "Name=tag:selector,Values=${selector_name}-selector" | jq -r .Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddresses[].PrivateDnsName)

# Write them into /etc/hosts
NODELIST=""
for host in $hosts; do
if [[ "$NODELIST" == "" ]]; then
NODELIST=$host
else
NODELIST=$NODELIST,$host
fi
done
# Extra sleep for good measure lol
sleep 10

# Write hostlist somewhere we can find it
sudo echo $NODELIST >> /opt/hostlist.txt
# Update the config files with our hosts - we need the ones from hostname
wget https://gist.githubusercontent.com/vsoch/275b865921605e54ab48087e8036dae2/raw/bb7c663abf8cd3f016847fdf668a7a241c768b27/write-hostlist.sh
chmod +x write-hostlist.sh
./write-hostlist.sh $selector_name-selector

0 comments on commit d8e9a3e

Please sign in to comment.