Deploying applications on Kubernetes can initially seem complex. Using Helm, Kubernetes’ package manager, simplifies the deployment process by letting you define reusable configurations in a single chart. Here’s a breakdown of how Kubernetes and Helm work, and the practical steps we used to get this testing project up and running.
How Kubernetes Works
Kubernetes (K8s) is a container orchestration platform designed to manage and automate the deployment, scaling, and operation of application containers. Key concepts in Kubernetes include:
- Pods: The smallest deployable units in Kubernetes, typically running a single container.
- Services: Enable network access to your pods.
- Deployments: Manage the desired state of your application, automatically scaling, updating, or rolling back as needed.
- Nodes: Worker machines in the Kubernetes cluster, which run the containers in your pods.
In this setup, Kubernetes allows us to manage SonarQube and Jenkins with reliability, making sure these services are always running, and automatically scaling when needed.
How Helm Works
Helm simplifies Kubernetes management by letting us bundle configuration files into Helm charts. A Helm chart is essentially a packaged application that contains all necessary configurations (YAML files) for deploying a specific service.
In our case:
- We use a values.yaml file to define configurations for each service (like SonarQube and Jenkins).
- Helm then reads these values and deploys the configured application to Kubernetes, handling service creation, persistent storage, resource limits, and more.
Configurations Used in the Setup
Here’s a quick look at the configurations we used for SonarQube and Jenkins.
SonarQube Configuration (sonarqube-values.yaml
)
The main configuration options we used for SonarQube include database settings, resource requests, and health checks.
postgresql:
postgresqlUsername: "sonarqube"
postgresqlPassword: "sonarqube123"
postgresqlDatabase: "sonarqube"
service:
type: LoadBalancer
resources:
requests:
cpu: "500m"
memory: "1Gi"
limits:
cpu: "1"
memory: "2Gi"
deployment:
containers:
- name: sonarqube
image: sonarqube:10.7.0-community
ports:
- containerPort: 9000
livenessProbe:
httpGet:
path: /api/system/liveness
port: 9000
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /api/system/status
port: 9000
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3
startupProbe:
httpGet:
path: /api/system/status
port: 9000
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 24
This configuration includes:
- Database Connection: Specifies PostgreSQL credentials.
- Service Type: Set as a
LoadBalancer
to expose SonarQube outside of the cluster. - Resource Requests/Limits: Defines the CPU and memory requirements.
- Probes: Liveness, readiness, and startup probes to monitor and manage SonarQube’s health.
Jenkins Configuration (jenkins-values.yaml
)
For Jenkins, we defined configurations for the admin user, service type, and persistent storage.
controller:
admin:
username: "admin"
password: "admin123"
serviceType: LoadBalancer
resources:
requests:
cpu: "500m"
memory: "512Mi"
limits:
cpu: "1000m"
memory: "1024Mi"
persistence:
enabled: true
size: 10Gi
In this setup:
- Admin Credentials: Configures default username and password.
- Service Type: Also set as a
LoadBalancer
for external access. - Resource Management: Defines CPU and memory allocations.
- Persistent Storage: Enables persistence to retain data even if the pod restarts.
Deployment Steps
- Prepare Kubernetes Cluster: We used DigitalOcean’s Kubernetes service to create a cluster with compatible version 1.29.9-do.4.
- Install Helm: This allows us to apply Helm charts to the Kubernetes cluster.
- Deploy SonarQube and Jenkins with Helm:
- Run
helm install sonarqube -f sonarqube-values.yaml
to deploy SonarQube with the specified settings. - Run
helm install jenkins -f jenkins-values.yaml
to deploy Jenkins.
- Run
- Verify Deployments:
- Use
kubectl get pods
to check the status of the deployments. - Access SonarQube and Jenkins through the external IPs provided by the
LoadBalancer
service.
- Use
- Easy Button:
- Download this repo, add your digital ocean API key to terraform.tfvars, and run
terraform apply
- Download this repo, add your digital ocean API key to terraform.tfvars, and run
Conclusion
This setup showcases how Kubernetes and Helm streamline the deployment and management of containerized applications. Kubernetes offers reliability and scalability, while Helm simplifies the configuration and deployment process, allowing you to manage complex applications like SonarQube and Jenkins with ease.
0 Comments