This repository leverages GitHub Actions to automate the creation of a Kubernetes cluster (v1.31.0) on provisioned EC2 instances on AWS. All you need is an AWS account and a GitHub account. Additionally, a workflow is provided to delete the Kubernetes cluster as long as the Terraform state file is available.
- AWS user credentials (Access key ID/Secret pair) with the necessary EC2 action rights. The minimum required permissions are detailed in the
aws_iam_policy.json. - An SSH key (note the name) generated in AWS, with the private key saved in .pem format.
- The ability to copy this repository and create your own repository (it is highly recommended to use a private repository as all artifacts are accessible by the public in a public repository).
- Save the following secrets for GitHub Actions in your repository. Visit this link for instructions:
AWS_ACCESS_KEY_ID: Access key of the AWS userAWS_SECRET_ACCESS_KEY: Secret key of the AWS userSSH_KEY_EC2: The entire content of the SSH key .pem file
- Go to the GitHub Actions tab, and on the left, choose the workflow
Create a k8s cluster. - On the right side, click
Run workflow, and enter the customization information:- Default AWS region to create all resources. Default is
us-east-1. - Number of worker nodes to be provisioned. Default is
1. - Machine type of the master node. Default is
t2.medium. - Machine type of the worker node. Default is
t2.medium. - Name of the SSH key on AWS to be used to access the EC2 instances.
- Default AWS region to create all resources. Default is
- Click
Run workflow. - Once the workflow completes successfully, download the artifact
kubeconfigto access the Kubernetes cluster.
We use the workflow Delete a k8s cluster to destroy a Kubernetes cluster. There are two options to use this workflow:
Note: Artifacts are saved in GitHub for up to 90 days. If it has been more than 90 days since the workflow was run, this method will not work.
- Enter the Run ID of the workflow
Create a k8s clusterthat contains the state file. Run ID can be found in the URL of the workflow run -https://github.com/owner/repo/actions/runs/<RUN_ID>. - Run
Delete a k8s clusterworkflow.
- Download the artifact
terraform_state_files2after a successful run of the workflowCreate a k8s cluster. Check this link for instructions. - Add the file to the repository, under the directory
automated-k8s-aws-setup/Terraform3. Then push the change. - Leave
Run IDas empty. Run the workflowDelete a k8s cluster.