Compare commits

..

9 Commits

Author SHA1 Message Date
7ac1ac9f8c Created placeholder for future folder structure
All checks were successful
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
Lint Code Base / run-lint (push) Successful in 37s
2024-10-18 17:11:15 +02:00
81288cdf4e Fixed typo
All checks were successful
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: MARKDOWN No errors were found in the linting process
--> Linted: NATURAL_LANGUAGE No errors were found in the linting process
Lint Code Base / run-lint (push) Successful in 38s
2024-10-18 16:59:25 +02:00
8f56a7e2a7 Fixed linter errors
Some checks failed
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: MARKDOWN No errors were found in the linting process
--> Linted: NATURAL_LANGUAGE Errors were detected, please view logs
Lint Code Base / run-lint (push) Failing after 36s
2024-10-18 16:53:49 +02:00
3f8c06cfe4 Fixed formatting
Some checks failed
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: MARKDOWN Errors were detected, please view logs
--> Linted: NATURAL_LANGUAGE Errors were detected, please view logs
Lint Code Base / run-lint (push) Failing after 33s
2024-10-18 16:49:28 +02:00
5c69bb29ff Improved readability
Some checks failed
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: MARKDOWN Errors were detected, please view logs
--> Linted: NATURAL_LANGUAGE Errors were detected, please view logs
Lint Code Base / run-lint (push) Failing after 32s
2024-10-18 16:48:23 +02:00
8de6a0166a Fixed formatting
Some checks failed
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: MARKDOWN Errors were detected, please view logs
--> Linted: NATURAL_LANGUAGE Errors were detected, please view logs
Lint Code Base / run-lint (push) Failing after 35s
2024-10-18 16:45:54 +02:00
eb3a97e403 Updated README.md
Some checks failed
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: MARKDOWN Errors were detected, please view logs
--> Linted: NATURAL_LANGUAGE Errors were detected, please view logs
Lint Code Base / run-lint (push) Failing after 37s
2024-10-18 16:43:25 +02:00
fec3446ecc Template for deploying with Helm
All checks were successful
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: TERRAFORM_TFLINT No errors were found in the linting process
--> Linted: TERRAFORM_TERRASCAN No errors were found in the linting process
Lint Code Base / run-lint (push) Successful in 48s
2024-10-18 15:33:22 +02:00
bb7393b05e Implemented CIS Kubernetes benchmark
All checks were successful
--> Linted: ANSIBLE No errors were found in the linting process
--> Linted: GITLEAKS No errors were found in the linting process
--> Linted: JSCPD No errors were found in the linting process
--> Linted: TERRAFORM_TFLINT No errors were found in the linting process
--> Linted: TERRAFORM_TERRASCAN No errors were found in the linting process
Lint Code Base / run-lint (push) Successful in 42s
2024-10-18 13:16:30 +02:00
3 changed files with 85 additions and 3 deletions

View File

@@ -0,0 +1,37 @@
# Terraform-Ansible-Helm Deployer
[![Super-Linter](https://github.com/doddophonique/tah-deploy/actions/workflows/super-linter.yml/badge.svg)](https://github.com/marketplace/actions/super-linter)
## Usage
From the `terraform/` folder:
```shell
terraform init
terraform plan
terraform apply
```
## Decisions and goals
The `terraform-provider-libvirt` has been chosen over Vagrant to deploy the VMs as a way to simplify the structure of the project. The choice over a cloud provider such as AWS or GCP has been done to not incur into billing cost during troubleshooting and deployments.
### Terraform script
The Terraform script roughly follows these steps:
1. Deploy 3 VMs (one master and two workers) with:
- 2 vCPUs;
- 2GB vRAM;
- 20GB of disk space;
- Ubuntu 24.04 LTS;
- An Ansible user.
2. Call an Ansible Playbook that:
1. Configures the master node and installs Kubernetes;
2. Configures the network for the Kubernetes cluster;
3. Configures the worker nodes and installs Kubernetes.
3. Create the `kiratech-test` namespace;
4. Run the CIS Kubernetes benchmark;
5. Copy the helm folder to the master node and install helm.
### Next steps
The script currently lacks:
- [ ] Capability of deploying an Helm application;
- [ ] Usage of Terraform outputs to populate Ansible files;
### CIS Kubernetes Benchmark
The CIS Benchamrk is one of (if not the) most popular benchmarks publicly available, and also has a simple way to implement it in a deployment pipeline using the [kube-bench](https://github.com/aquasecurity/kube-bench) implementation.
## Linting
The project uses GitHub Actions as a CI tool, running [super-linter](https://github.com/super-linter/super-linter) on the entire codebase.

0
helm/.placeholder Normal file
View File

View File

@@ -184,6 +184,51 @@ resource null_resource create_namespace {
provisioner "remote-exec" { provisioner "remote-exec" {
inline = ["sudo mkdir ~/.kube", "sudo cp /etc/kubernetes/admin.conf ~/.kube/", "sudo mv ~/.kube/admin.conf ~/.kube/config", "sudo service kubelet restart", "sudo kubectl --kubeconfig ~/.kube/config create namespace kiratech-test"] inline = ["sudo mkdir ~/.kube", "sudo cp /etc/kubernetes/admin.conf ~/.kube/", "sudo mv ~/.kube/admin.conf ~/.kube/config", "sudo service kubelet restart", "sudo kubectl --kubeconfig ~/.kube/config create namespace kiratech-test"]
connection {
host = libvirt_domain.k8s_masters[0].network_interface[0].addresses[0]
type = "ssh"
user = "ansible"
private_key = data.template_file.private_key.rendered
}
}
}
resource null_resource run_benchmark {
depends_on = [
null_resource.create_namespace
]
provisioner "remote-exec" {
inline = ["curl https://raw.githubusercontent.com/aquasecurity/kube-bench/refs/heads/main/job-master.yaml > job-master.yaml", "kubectl --kubeconfig ~/.kube/config apply -f job-master.yaml", "rm job-master.yaml"]
connection {
host = libvirt_domain.k8s_masters[0].network_interface[0].addresses[0]
type = "ssh"
user = "ansible"
private_key = data.template_file.private_key.rendered
}
}
}
resource null_resource deploy_helm {
depends_on = [
null_resource.run_benchmark
]
provisioner "local-exec" {
command = "scp -i ${path.module}/.local/.ssh/id_rsa -r ../helm ansible@${libvirt_domain.k8s_masters[0].network_interface[0].addresses[0]}:/home/ansible/helm"
}
# https://helm.sh/docs/intro/install/#from-apt-debianubuntu
provisioner "remote-exec" {
inline = [
"curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null",
"sudo apt-get install apt-transport-https --yes",
"echo \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main\" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list",
"sudo apt-get update",
"sudo apt-get install helm"
]
connection { connection {
host = libvirt_domain.k8s_masters[0].network_interface[0].addresses[0] host = libvirt_domain.k8s_masters[0].network_interface[0].addresses[0]
type = "ssh" type = "ssh"