- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
Hey there, DevOps warrior! ? Let’s talk about a nightmare we’ve all had:
It’s 2 AM. Your app just went viral, and your servers are melting faster than a popsicle in July. You’re frantically scaling pods manually, praying your users don’t notice the 500 errors. Sound familiar?
What if you could automate everything—deployments, scaling, rollbacks—while sipping coffee? Enter GitLab CI/CD + Kubernetes: the dynamic duo that’ll turn you into the calmest engineer in the room.
Why GitLab CI + Kubernetes? (Spoiler: It’s Like DevOps Autopilot)
Let’s turn you into a Kubernetes CI/CD wizard.
Step 1: Connect GitLab to Your Kubernetes Cluster
A. Link Your Cluster
![Screenshot: GitLab Kubernetes cluster integration page]
B. Install GitLab’s Agent (Optional but Highly Recommended)
The GitLab Agent lets you:
helm upgrade --install gitlab-agent gitlab/gitlab-agent \
--namespace gitlab-agent \
--set image.tag=v16.0.0 \
--set config.token=YOUR_AGENT_TOKEN
Step 2: Build a Killer Deployment Pipeline
Here’s a .gitlab-ci.yml pipeline that:
stages:
- build
- deploy
build:
stage: build
image: docker:24
services:
- docker:dind
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
deploy:
stage: deploy
image: bitnami/kubectl:latest
script:
- kubectl apply -f kubernetes/deployment.yaml
- kubectl apply -f kubernetes/hpa.yaml # Apply Horizontal Pod Autoscaler
environment:
name: production
url:
Step 3: Auto-Scaling 101 (Because Traffic Spikes Happen)
A. Horizontal Pod Autoscaler (HPA)
Add hpa.yaml to scale pods based on CPU/memory:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
B. Cluster Autoscaler
For cloud clusters (AWS/GCP), the Cluster Autoscaler automatically adds nodes when pods can’t schedule.
Pro Tips to Avoid Facepalms ?
rollback:
script:
- kubectl rollout undo deployment/myapp
when: manual
Acme Corp’s e-commerce site had a Black Friday traffic tsunami. Their old setup crashed. After switching to GitLab CI + Kubernetes:
deploy:
script:
- kubectl apply ...
rules:
- if: $CI_PIPELINE_SOURCE == "chat"
Your DevOps Superpower Awaits
GitLab CI + Kubernetes isn’t just a toolchain—it’s peace of mind. You’ll:
Next Steps:
Hit a snag? Drop a comment below. Let’s debug together! ?️
Now go automate ALL THE THINGS. ?
P.S. Your future self (well-rested, stress-free, and sipping coffee) says: “Thank you.”
It’s 2 AM. Your app just went viral, and your servers are melting faster than a popsicle in July. You’re frantically scaling pods manually, praying your users don’t notice the 500 errors. Sound familiar?
What if you could automate everything—deployments, scaling, rollbacks—while sipping coffee? Enter GitLab CI/CD + Kubernetes: the dynamic duo that’ll turn you into the calmest engineer in the room.
Why GitLab CI + Kubernetes? (Spoiler: It’s Like DevOps Autopilot)
- Zero Downtime Deployments: Ship updates while users happily browse.
- Auto-Scaling: Kubernetes scales pods up/down based on traffic. No more midnight panic.
- GitOps Bliss: Define infrastructure as code (IaC) and let GitLab manage the rest.
Let’s turn you into a Kubernetes CI/CD wizard.
Step 1: Connect GitLab to Your Kubernetes Cluster
A. Link Your Cluster
- In GitLab, go to Infrastructure > Kubernetes.
- Click Add Kubernetes Cluster and follow the prompts.
- Copy-paste your kubeconfig or let GitLab auto-generate one.
![Screenshot: GitLab Kubernetes cluster integration page]
B. Install GitLab’s Agent (Optional but Highly Recommended)
The GitLab Agent lets you:
- Securely connect to your cluster.
- Automatically sync manifests.
- Monitor deployments from GitLab’s UI.
helm upgrade --install gitlab-agent gitlab/gitlab-agent \
--namespace gitlab-agent \
--set image.tag=v16.0.0 \
--set config.token=YOUR_AGENT_TOKEN
Step 2: Build a Killer Deployment Pipeline
Here’s a .gitlab-ci.yml pipeline that:
- Builds a Docker image.
- Deploys to Kubernetes.
- Auto-scales based on traffic.
stages:
- build
- deploy
build:
stage: build
image: docker:24
services:
- docker:dind
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
deploy:
stage: deploy
image: bitnami/kubectl:latest
script:
- kubectl apply -f kubernetes/deployment.yaml
- kubectl apply -f kubernetes/hpa.yaml # Apply Horizontal Pod Autoscaler
environment:
name: production
url:
Step 3: Auto-Scaling 101 (Because Traffic Spikes Happen)
A. Horizontal Pod Autoscaler (HPA)
Add hpa.yaml to scale pods based on CPU/memory:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
B. Cluster Autoscaler
For cloud clusters (AWS/GCP), the Cluster Autoscaler automatically adds nodes when pods can’t schedule.
Pro Tips to Avoid Facepalms ?
- Test Rollbacks:
rollback:
script:
- kubectl rollout undo deployment/myapp
when: manual
- Use GitLab Environments: Track deployments, view logs, and monitor directly in GitLab.
- Limit Permissions: Use RBAC to restrict GitLab’s access to only what it needs.
Acme Corp’s e-commerce site had a Black Friday traffic tsunami. Their old setup crashed. After switching to GitLab CI + Kubernetes:
- Auto-scaling handled 10x traffic spikes.
- Rollbacks fixed a bad deploy in 30 seconds.
- GitLab’s monitoring spotted a memory leak before users did.
- Canary Deployments: Split traffic between old/new versions with Flagger + GitLab.
- Spot Instances: Save $$$ by auto-scaling with AWS Spot or GCP Preemptible VMs.
- ChatOps: Trigger deployments via Slack:
deploy:
script:
- kubectl apply ...
rules:
- if: $CI_PIPELINE_SOURCE == "chat"
Your DevOps Superpower Awaits
GitLab CI + Kubernetes isn’t just a toolchain—it’s peace of mind. You’ll:
- Deploy fearlessly (even on Fridays ?).
- Sleep through traffic spikes.
- Become the office hero.
Next Steps:
- Connect your cluster to GitLab.
- Steal the pipeline above.
- Go deploy something spectacular.
Hit a snag? Drop a comment below. Let’s debug together! ?️
Now go automate ALL THE THINGS. ?
P.S. Your future self (well-rested, stress-free, and sipping coffee) says: “Thank you.”