{"id":22451968,"url":"https://github.com/odennav/terraform-aws-vpc-kubespray","last_synced_at":"2025-08-02T00:32:31.857Z","repository":{"id":225247361,"uuid":"765428070","full_name":"odennav/terraform-aws-vpc-kubespray","owner":"odennav","description":"Provision VPC with Terraform \u0026 deploy a Kubernetes Cluster in a 3-Tier architecture on AWS","archived":false,"fork":false,"pushed_at":"2024-06-20T23:04:16.000Z","size":3422,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T04:41:22.911Z","etag":null,"topics":["ansible","automation","aws","aws-ec2","aws-vpc","aws-vpc-subnet","database","database-subnets","internet-gateway","kubernetes","kubernetes-cluster","kubernetes-deployment","kubespray","nat-gateway","private-subnets","public-subnets","security-policies","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/odennav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-29T22:35:45.000Z","updated_at":"2024-06-21T04:41:33.617Z","dependencies_parsed_at":"2024-06-21T04:41:29.426Z","dependency_job_id":"fc812481-2ac6-43d2-a3b8-c986ef1d0f48","html_url":"https://github.com/odennav/terraform-aws-vpc-kubespray","commit_stats":null,"previous_names":["odennav/terraform-k8s-aws_ec2","odennav/terraform-kubernetes-aws-ec2","odennav/terraform-aws-vpc-kubespray"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odennav%2Fterraform-aws-vpc-kubespray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odennav%2Fterraform-aws-vpc-kubespray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odennav%2Fterraform-aws-vpc-kubespray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odennav%2Fterraform-aws-vpc-kubespray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/odennav","download_url":"https://codeload.github.com/odennav/terraform-aws-vpc-kubespray/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228419606,"owners_count":17916772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","automation","aws","aws-ec2","aws-vpc","aws-vpc-subnet","database","database-subnets","internet-gateway","kubernetes","kubernetes-cluster","kubernetes-deployment","kubespray","nat-gateway","private-subnets","public-subnets","security-policies","terraform"],"created_at":"2024-12-06T06:09:25.083Z","updated_at":"2025-08-02T00:32:31.779Z","avatar_url":"https://github.com/odennav.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"##  Provision VPC in AWS \u0026 Deploy a Kubernetes Cluster  \n\nThis project uses Terraform to deploy a 3-Tier Architecture on AWS which consists of the following:\n\n- Virtual Private Cloud\n\n- Private, public and database subnets.\n\n- Bastion, private and database EC2 instances.\n\n- Internet gateway for Bastion EC2 instances.\n\n- NAT gateway for private EC2 instances to communicate with the internet.\n\n- Elastic IPs assigned for NAT gateways.\n\nNo routes created from NAT gateway to database instances.\n\n### Requirements\n\n- Install [Terraform](https://developer.hashicorp.com/terraform/install)\n\n- Install [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)\n\n- Generate key pair for connection to EC2 instances in AWS console. Name it `terraform-key`. Choose `RSA` key pair type and use `.pem` key file format.\n\n- Minimum required version of Kubernetes is **`v1.27`**\n\nShell scripts used to automate deployment of kubernetes cluster to private EC2 instances with kubespray.\n\nInventory list for ansible is dynamically built with `.tpl` template.\n\n\n### Getting Started\n\n\nClone this repository to local machine\n```bash\ncd /\ngit clone git@github.com:odennav/terraform-aws-vpc-kubespray.git\ncd terraform-kubernetes-aws-vpc-kubespray/terraform\n```\n\n\nImplement terraform commands sequentially in local machine to create the AWS infrastructure.\n\nInitialize terraform working directory\n\n```bash\nterraform init\n```\n\nValidate the syntax of the terraform configuration files\n```bash\nterraform validate\n```\n\nCreate an execution plan that describes the changes terraform will make to the infrastructure\n```bash\nterraform plan\n```\n\nApply the changes described in execution plan\n```bash\nterraform apply -auto-approve\n```\nCheck AWS console for instances created and running\n\n\n![ec2](https://github.com/odennav/terraform-k8s-aws_ec2/blob/main/docs/ec2instances-shot.PNG)\n\n-----\n   \nUse the `.pem` key from AWS to SSH into the public EC2 instance.\n\nIPv4 address of public EC2 instance will be shown in terraform outputs.\n```bash\nssh -i private-key/terraform-key.pem ec2-user@\u003cipaddress\u003e\n```\nIts possible to use public EC2 instance as a jumpbox to ssh into private EC2 instances within the VPC.\n\nChange root password upon first-Login to `dev-Control` machine\n```bash\nsudo passwd\n```\n\nSwitch to root user.\n\nAdd new user to sudo group. In this case new user is `odennav-admin`\n```bash\nsudo useradd odennav-admin\nsudo usermod -aG wheel odennav-admin\n```\n\nTest sudo privileges by switching to new user\n```bash\nsu - odennav-admin\nsudo ls /root\n```\n\nYou'll notice prompt to enter your user password.\n\nTo disable this prompt for every sudo command, implement the following:\n\nAdd sudoers file for `odennav-admin` user\n```bash\ncd /etc/sudoers.d/\nsudo echo \"odennav-admin ALL=(ALL) NOPASSWD: ALL\" \u003e odennav-admin\n```\nSet permissions for sudoers file\n```bash\nsudo chmod 0440 odennav-admin\n```\n\nUpdate yum package manager\n```bash\nsudo yum update -y\nsudo yum upgrade -y\n```\n\nConfirm Git was installed by terraform\n```bash\ngit --version\n```\n\nConfirm terraform-key was transferred to public EC2 instance by null provisioner\n   \n`terraform-key.pem` should be copied to another folder because it will be deleted if node is restarted or shutdown\n```bash\nls -la /tmp/terraform-key.pem\ncp /tmp/terraform-key.pem /\n```\n\nChange permissions of terraform-key.pem file\n   \nSSH test will fail if permissions of `.pem` key are not secure enough\n```bash\nsudo chmod 400 /tmp/terraform-key.pem\n```\n\n\nClone this repository to `control-dev` node\n```bash\ncd /\ngit clone git@github.com:odennav/terraform-aws-vpc-kubespray.git\ngit clone git@github.com:kubernetes-sigs/kubespray.git\n```\n\nCopy IPv4 adresses of private EC2 instances deployed by Terraform\n   \nCheck IPv4 addresses in `inventory` file and input them in `bash-scripts/ipaddr-list.txt`\n   \nDon't change format seen in `.txt` file, ip addresses will be read by the shell scripts.\n   \nFor security reasons, don't share your private ips. \n\n-----\n\nInstall yum and python utilities\n\n```bash\nsudo chmod 770 dependencies-install\nsudo ./dependencies-install\n```\n\nSetup nodes for Kubernetes cluster\n    \n```bash\nsudo chmod 770 kubespray-deploy.sh\nsudo ./kubespray-env-build.sh\n```\n   \nChange directory to your local kubespray repository and execute the ansilbe playbook to deploy kubernetes cluster with kubespray\n   \n```bash\ncd /kubespray\nansible-playbook -i inventory/mycluster/hosts.yaml --become --become-user=odennav-admin cluster.yml\n```\n\n-----\n\n#### Destroying Resources(Optional)\n\nTo tear down the infrastructure created by Terraform.\n\n```bash\nterraform destroy\n```\n\n-----\n\nEnjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodennav%2Fterraform-aws-vpc-kubespray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fodennav%2Fterraform-aws-vpc-kubespray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodennav%2Fterraform-aws-vpc-kubespray/lists"}