-
Notifications
You must be signed in to change notification settings - Fork 277
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
add dev setup guide #656
Changes from all commits
fc0dedb
5d15aea
0e37d6c
65448f7
5b612aa
f72e407
d495557
94254c4
d122bfd
dd3878f
0434277
f71b780
4807978
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,4 +35,3 @@ jobs: | |
|
|
||
| - name: make test | ||
| run: make test | ||
| working-directory: ./src | ||
| 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 | ||
| *~ |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| # 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. Specify an EKS Cluster | ||
|
|
||
| *Tip:* Several steps in this guide, and utility scripts, use environment variables. Saving these environment variables in a file, or using a shell extension that manages sets of environment variables, will make it easier to restore your development environment in a new shell. | ||
|
|
||
| ```sh | ||
| export CLUSTER_NAME=<name> | ||
| export AWS_REGION=<region> | ||
| ``` | ||
|
|
||
| ### 2.1. (Optional) Create the 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. | ||
|
|
||
| ## 3. 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}" | ||
| ``` | ||
|
|
||
| Resources created: | ||
|
|
||
| * `ServiceAccountPolicy` - IAM Managed Policy that allows access to Auto Scaling Groups, EC2, and SQS. | ||
|
|
||
| ```sh | ||
| 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}" | ||
| ``` | ||
|
|
||
| Resources created: | ||
|
|
||
| * `ControllerRespository` - ECR Respository for images of the Kubernetes controller. | ||
| * `WebhookRespository` - ECR Repository for images of the Kubernetes admission webhook. | ||
|
|
||
| ```sh | ||
| 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}" | ||
| ``` | ||
|
|
||
| Resources created: | ||
|
|
||
| * `Queue` - SQS Queue that will receive messages from EventBridge | ||
| * `AutoScalingTerminationRule` - EventBridge Rule to route instance-terminate lifecycle action messages from Auto Scaling Groups to `Queue` | ||
| * `RebalanceRecommendationRule` - EventBridge Rule to route rebalance recommendation messages from EC2 to `Queue` | ||
| * `ScheduledChangeRule` - EventBridge Rule to route scheduled change messages from AWS Health to `Queue` | ||
| * `SpotInterruptionRule` - EventBridge Rule to route EC2 Spot interruption notice messages from EC2 to `Queue` | ||
| * `StateChangeRule` - EventBridgeRule to route state change messages from EC2 to `Queue` | ||
|
|
||
| ## 4. 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') | ||
| ``` | ||
|
|
||
| ## 5. 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 | ||
| ``` | ||
|
|
||
| ## 6. Build and deploy controller to EKS cluster | ||
|
|
||
| ```sh | ||
| make apply | ||
| ``` | ||
|
|
||
| ### 6.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 | ||
| ``` | ||
|
|
||
| ## 7. 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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. | ||
|
|
||
| ## 8. 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}" | ||
| ``` | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.