Skip to content

add dev setup guide #656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ jobs:

- name: make test
run: make test
working-directory: ./src
22 changes: 12 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test
# Tools directory.
bin/

# Generated symlinks.
cmd/**/kodata/

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.idea/

# Output of the go build for the cmd binary
/node-termination-handler
# Kubernetes Generated files - skip generated files, except for vendored files
!vendor/**/zz_generated.*

### Go Patch ###
/vendor/
/Godeps/
/build/
# Editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
73 changes: 0 additions & 73 deletions BUILD.md

This file was deleted.

138 changes: 138 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Setup Development Environment

## 1. Clone the repo

```sh
git clone --branch v2 https://github.com/aws/aws-node-termination-handler.git nthv2
cd nthv2
```

## 2. Set environment variables

*Tip:* Several steps in this guide, and utility scripts, use environment variables. Saving these environment variables in a file, or using a shell extension like [direnv](https://direnv.net), will make it easy to restore your development environment in a new shell instance.

```sh
export CLUSTER_NAME=<name>
export AWS_REGION=<region>
```

## 3. Create a basic EKS Cluster

Skip this set if you already have an EKS cluster.

```sh
envsubst <resources/eks-cluster.yaml.tmpl | eksctl create cluster --kubeconfig "${PWD}/kubeconfig" -f -

export KUBECONFIG="$PWD/kubeconfig"
```

If you do not want to use `envsubst` you can copy the template file and substitute the referenced values.

## 4. Create Infrastructure

```sh
export INFRASTRUCTURE_STACK_NAME="nth-${CLUSTER_NAME}"

aws cloudformation deploy \
--template-file resources/infrastructure.yaml \
--stack-name "${INFRASTRUCTURE_STACK_NAME}" \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides ClusterName="${CLUSTER_NAME}"

export DEV_INFRASTRUCTURE_STACK_NAME="${INFRASTRUCTURE_STACK_NAME}-dev"

aws cloudformation deploy \
--template-file resources/dev-infrastructure.yaml \
--stack-name "${DEV_INFRASTRUCTURE_STACK_NAME}" \
--parameter-overrides ClusterName="${CLUSTER_NAME}"

export QUEUE_NAME=<name>
export QUEUE_STACK_NAME="${INFRASTRUCTURE_STACK_NAME}-queue-${QUEUE_NAME}"

aws cloudformation deploy \
--template-file resources/queue-infrastructure.yaml \
--stack-name "${QUEUE_STACK_NAME}" \
--parameter-overrides \
ClusterName="${CLUSTER_NAME}" \
QueueName="${QUEUE_NAME}"
```

## 5. Connect Infrastructure to EKS Cluster

```sh
export CLUSTER_NAMESPACE=<namespace>
export SERVICE_ACCOUNT_NAME="nth-${CLUSTER_NAME}-serviceaccount"

eksctl create iamserviceaccount \
--cluster "${CLUSTER_NAME}" \
--namespace "${CLUSTER_NAMESPACE}" \
--name "${SERVICE_ACCOUNT_NAME}" \
--role-name "${SERVICE_ACCOUNT_NAME}" \
--attach-policy-arn $(./scripts/get-cfn-stack-output.sh "${INFRASTRUCTURE_STACK_NAME}" ServiceAccountPolicyARN) \
--role-only \
--approve

export SERVICE_ACCOUNT_ROLE_ARN=$(eksctl get iamserviceaccount \
--cluster "${CLUSTER_NAME}" \
--namespace "${CLUSTER_NAMESPACE}" \
--name "${SERVICE_ACCOUNT_NAME}" \
--output json | \
jq -r '.[0].status.roleARN')
```

## 6. Configure and Login to Image Repository

```sh
export KO_DOCKER_REPO=$(./scripts/get-cfn-stack-output.sh "${DEV_INFRASTRUCTURE_STACK_NAME}" RepositoryBaseURI)

./scripts/docker-login-ecr.sh
```

## 7. Build and deploy controller to EKS cluster

```sh
make apply
```

### 7.1. (Optional) Providing additional Helm values

The `apply` target sets some Helm chart values for you based on environment variables. To set additional Helm values use the `HELM_OPTS` make argument. For example:

```sh
make HELM_OPTS='--set logging.level=debug' apply
```

## 8. Define and deploy a Terminator to EKS cluster

```sh
export TERMINATOR_NAME=<name>
export QUEUE_URL=$(./scripts/get-cfn-stack-output.sh "${QUEUE_STACK_NAME}" QueueURL)

envsubst <resources/terminator.yaml.tmpl >terminator-${TERMINATOR_NAME}.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to previous section, I think it's better to state what needs to be done (substitution) and let user decide how to do it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I view this as a how-to guide. When I'm reading a how-to guide I prefer clear and detailed instructions rather than the implementation being left as "an exercise for the reader".

Specifically referencing the use of envsubst: below the code block, alternate instructions are given if the reader does not wish to use that tool.


kubectl apply -f terminator-${TERMINATOR_NAME}.yaml
```

If you do not want to use `envsubst` you can copy the template file and substitute the referenced values.

## 9. Remove deployed controller from EKS cluster

```sh
make delete
```

# Tear down Development Environment

```sh
make delete

eksctl delete cluster --name "${CLUSTER_NAME}"

aws cloudformation delete-stack --stack-name "${QUEUE_STACK_NAME}"

./scripts/clear-image-repo.sh "$(./scripts/get-cfn-stack-output.sh ${DEV_INFRASTRUCTURE_STACK_NAME} ControllerRepositoryName)"
./scripts/clear-image-repo.sh "$(./scripts/get-cfn-stack-output.sh ${DEV_INFRASTRUCTURE_STACK_NAME} WebhookRepositoryName)"
aws cloudformation delete-stack --stack-name "${DEV_INFRASTRUCTURE_STACK_NAME}"

aws cloudformation delete-stack --stack-name "${INFRASTRUCTURE_STACK_NAME}"
```
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Makefile → Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CONTROLLER_GEN = $(BIN_DIR)controller-gen
KO = $(BIN_DIR)/ko
SETUP_ENVTEST = $(BIN_DIR)/setup-envtest
GINKGO = $(BIN_DIR)/ginkgo
HELM_BASE_OPTS ?= --set serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn=${NTHV2_IAM_ROLE_ARN}
HELM_BASE_OPTS ?= --set aws.region=${AWS_REGION},serviceAccount.name=${SERVICE_ACCOUNT_NAME},serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn=${SERVICE_ACCOUNT_ROLE_ARN}
GINKGO_BASE_OPTS ?= --coverpkg $(shell head -n 1 $(PROJECT_DIR)/go.mod | cut -s -d ' ' -f 2)/pkg/...
KODATA = \
cmd/controller/kodata/HEAD \
Expand Down
File renamed without changes.
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

<h4>Gracefully handle EC2 instance shutdown within Kubernetes</h4>

### Community Meeting
NTH community meeting is hosted on a monthly cadence. Everyone is welcome to participate!
* **When:** first Tuesday of every month from 9:00-9:30AM PST | [Calendar Event (ics)](https://raw.githubusercontent.com/aws/aws-node-termination-handler/main/assets/nth-community-meeting.ics)
* **Where:** [Chime meeting bridge](https://chime.aws/6502066216)


## Project Summary

This project ensures that the Kubernetes control plane responds appropriately to events that can cause your EC2 instance to become unavailable, such as [EC2 maintenance events](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-instances-status-check_sched.html), [EC2 Spot interruptions](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-interruptions.html), [ASG Scale-In](https://docs.aws.amazon.com/autoscaling/ec2/userguide/AutoScalingGroupLifecycle.html#as-lifecycle-scale-in), [ASG AZ Rebalance](https://docs.aws.amazon.com/autoscaling/ec2/userguide/auto-scaling-benefits.html#AutoScalingBehavior.InstanceUsage), and EC2 Instance Termination via the API or Console. If not handled, your application code may not stop gracefully, take longer to recover full availability, or accidentally schedule work to nodes that are going down.
Expand All @@ -23,20 +17,15 @@ This project ensures that the Kubernetes control plane responds appropriately to
- Webhook feature to send shutdown or restart notification messages
- Unit & Integration Tests

## Installation and Configuration

TBD

### Installation and Configuration

TBD
## Getting Started

### Infrastructure Setup

TBD

## Building
For build instructions please consult [BUILD.md](./BUILD.md).
### Installation and Configuration

For a full list of inputs see the Helm chart [README.md](./charts/aws-node-termination-handler-2/README.md).

## Metrics

Expand All @@ -50,6 +39,7 @@ TBD
## Contributing
Contributions are welcome! Please read our [guidelines](https://github.com/aws/aws-node-termination-handler/blob/main/CONTRIBUTING.md) and our [Code of Conduct](https://github.com/aws/aws-node-termination-handler/blob/main/CODE_OF_CONDUCT.md)

To setup a development environment see the instructions in [DEVELOPMENT.md](./DEVELOPMENT.md).

## License
This project is licensed under the Apache-2.0 License.

49 changes: 0 additions & 49 deletions assets/nth-community-meeting.ics

This file was deleted.

Loading