These exercises are designed to build upon the local K3s setup using Terraform and Ansible
Exercise 1: Enhance Backend Deployment
Modify the backend deployment to use the latest Kubernetes features for improved resilience and scalability.
- Update the Terraform configuration to use a Deployment with a RollingUpdate strategy.
- Implement readiness and liveness probes in the backend container specification.
- Add resource requests and limits to the backend container.
- Use the Ansible kubernetes module to create a HorizontalPodAutoscaler for the backend.
Exercise 2: Implement Secure Ingress
Add an Ingress resource to route external traffic to your services securely.
- Use Terraform to deploy an Ingress controller (e.g., Nginx Ingress Controller).
- Create an Ingress resource in Terraform to route traffic to your frontend and backend services.
- Implement TLS termination using a self-signed certificate (use Ansible to generate the certificate).
- Update the Ansible playbook to configure any necessary DNS settings for local testing.
Exercise 3: Enhance Database Security
Improve the security of the PostgreSQL database deployment.
- Use Terraform to create a Kubernetes Secret for the database credentials.
- Modify the Ansible playbook to use this Secret in the PostgreSQL deployment.
- Implement a NetworkPolicy using Terraform to restrict database access to only the backend service.
- Use Ansible to configure regular database backups to a persistent volume.
Exercise 4: Implement GitOps with ArgoCD and GitLab CI
Set up a GitOps workflow using ArgoCD for continuous deployment and GitLab CI for continuous integration.
- Use Terraform to install ArgoCD in the K3s cluster.
- Create a GitLab repository to store your Kubernetes manifests.
- Use Ansible to configure ArgoCD to sync your GitLab repository with the cluster.
- Implement a GitLab CI pipeline that:
a. Builds and tests your application code
b. Updates the Kubernetes manifests in the GitLab repository when changes are made to your application code
- Configure ArgoCD to automatically sync changes from the GitLab repository to the cluster.
Exercise 5: Monitoring and Logging
Set up a basic monitoring and logging stack.
- Use Terraform to deploy Prometheus and Grafana for monitoring.
- Implement Loki and Promtail for log aggregation using Terraform.
- Create an Ansible playbook to configure custom dashboards in Grafana.
- Implement alerts in Prometheus and use Ansible to configure alert routing.
Remember to test your changes thoroughly and ensure that both Terraform and Ansible remain idempotent throughout these exercises.
Feeling stuck? Click here to see the solution