Modern yazılım geliştirmede CI/CD (Continuous Integration/Continuous Deployment) vazgeçilmez bir süreçtir. Bu yazıda, Proxmox sanal sunucu altyapısı üzerinde Kubernetes cluster'ı kurarak ve GitLab CI/CD ile entegre ederek tamamen otomatik bir deployment pipeline'ı nasıl oluşturacağınızı göstereceğim.
Mimari Genel Bakış
Oluşturacağımız sistemin ana bileşenleri:
- Proxmox VE: Hypervisor ve VM yönetimi
- Kubernetes: Container orchestration
- GitLab: CI/CD ve source control
- Docker Registry: Container image storage
- Cloudflare: DNS ve CDN
Proxmox Kurulumu ve Yapılandırması
Proxmox, KVM tabanlı güçlü bir sanal sunucu platformudur. İlk adım olarak VM'lerimizi oluşturacağız.
VM Template Oluşturma
# Ubuntu cloud image indir
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
# VM oluştur
qm create 9000 --memory 2048 --cores 2 --name ubuntu-cloud --net0 virtio,bridge=vmbr0
qm importdisk 9000 jammy-server-cloudimg-amd64.img local-lvm
qm set 9000 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-9000-disk-0
qm set 9000 --boot c --bootdisk scsi0
qm set 9000 --ide2 local-lvm:cloudinit
qm set 9000 --serial0 socket --vga serial0
qm set 9000 --agent enabled=1
# Template'e çevir
qm template 9000
Kubernetes Cluster Kurulumu
Template'imizi kullanarak Kubernetes node'larımızı oluşturalım.
Master Node Kurulumu
# kubeadm, kubelet, kubectl kur
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
# Cluster'ı başlat
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
# kubectl yapılandır
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
CNI Plugin (Calico) Kurulumu
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/custom-resources.yaml
GitLab Runner Kurulumu
GitLab Runner'ı Kubernetes üzerinde çalıştıracağız.
apiVersion: v1
kind: Namespace
metadata:
name: gitlab-runner
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab-runner
namespace: gitlab-runner
spec:
replicas: 1
selector:
matchLabels:
app: gitlab-runner
template:
metadata:
labels:
app: gitlab-runner
spec:
containers:
- name: gitlab-runner
image: gitlab/gitlab-runner:latest
env:
- name: RUNNER_EXECUTOR
value: "kubernetes"
volumeMounts:
- name: config
mountPath: /etc/gitlab-runner
volumes:
- name: config
configMap:
name: gitlab-runner-config
CI/CD Pipeline Yapılandırması
.gitlab-ci.yml dosyamız:
stages:
- build
- test
- deploy
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
build:
stage: build
image: docker:latest
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 set image deployment/myapp myapp=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -n production
- kubectl rollout status deployment/myapp -n production
Docker Registry Entegrasyonu
Private Docker registry'mizi Kubernetes üzerinde çalıştıralım:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: docker-registry-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: docker-registry
spec:
replicas: 1
selector:
matchLabels:
app: docker-registry
template:
metadata:
labels:
app: docker-registry
spec:
containers:
- name: registry
image: registry:2
ports:
- containerPort: 5000
volumeMounts:
- name: storage
mountPath: /var/lib/registry
volumes:
- name: storage
persistentVolumeClaim:
claimName: docker-registry-pvc
Cloudflare DNS ve CDN
Cloudflare üzerinden domain yönetimi ve CDN kurulumu:
- Domain'i Cloudflare'e ekle
- DNS kayıtlarını güncelle
- SSL/TLS sertifikası aktive et
- Page Rules ile cache stratejisi belirle
# Kubernetes'e Cloudflare API token'ı ekle
kubectl create secret generic cloudflare-api-token \
--from-literal=api-token=YOUR_TOKEN \
-n kube-system
Monitoring ve Logging
Prometheus ve Grafana ile monitoring:
# Prometheus Operator kur
kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/bundle.yaml
# Grafana kur
helm repo add grafana https://grafana.github.io/helm-charts
helm install grafana grafana/grafana -n monitoring --create-namespace
Otomatik Ölçeklendirme
Horizontal Pod Autoscaler (HPA):
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: 70
Backup Stratejisi
Velero ile Kubernetes backup:
# Velero kur
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.8.0 \
--bucket velero-backups \
--backup-location-config region=eu-west-1 \
--snapshot-location-config region=eu-west-1
# Otomatik backup schedule
velero schedule create daily-backup --schedule="0 2 * * *"
Güvenlik Önlemleri
- Network Policies: Pod'lar arası iletişimi kısıtla
- RBAC: Role-based access control uygula
- Pod Security Standards: Security context'leri zorla
- Secret Encryption: Secrets'ları encrypt et
- Image Scanning: Container image'ları tara
Sonuç
Bu mimari ile:
- ✅ Tamamen otomatik CI/CD pipeline
- ✅ Ölçeklenebilir Kubernetes cluster
- ✅ Monitoring ve alerting
- ✅ Otomatik backup
- ✅ CDN ve DNS yönetimi
Proxmox + Kubernetes kombinasyonu, güçlü ve esnek bir altyapı sağlar. GitLab CI/CD entegrasyonu ile development'tan production'a kadar tüm süreç otomatize edilir.
"Otomatize edilebilecek her şey otomatize edilmelidir. Zaman, en değerli kaynağımızdır."