Skip to content

Kubernetes

Huy Nguyen edited this page Apr 5, 2025 · 2 revisions

Kubernetes Deployment

This guide explains how to deploy Mixcore CMS on Kubernetes clusters for scalable, resilient production environments.

Prerequisites

  • A working Kubernetes cluster (local or cloud-based)
  • kubectl command-line tool
  • Helm package manager (optional but recommended)
  • Docker image of Mixcore CMS (see Docker Deployment)
  • Basic knowledge of Kubernetes concepts

Deployment Architecture

When deployed on Kubernetes, Mixcore CMS typically consists of:

  • Application pods running the Mixcore CMS containers
  • Database service (SQL Server or other supported database)
  • Storage volumes for persistence
  • Ingress controller for routing HTTP traffic
  • Secrets for sensitive configuration
graph TD
    A[Ingress] --> B[Mixcore Service]
    B --> C[Mixcore Pods]
    C --> D[Database Service]
    D --> E[Database Pods]
    C --> F[Persistent Volumes]
    E --> G[Database Volumes]
Loading

Basic Deployment

1. Create Namespace

kubectl create namespace mixcore

2. Database Deployment

Create the SQL Server deployment YAML file mixcore-db.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sqlserver
  namespace: mixcore
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sqlserver
  template:
    metadata:
      labels:
        app: sqlserver
    spec:
      containers:
      - name: sqlserver
        image: mcr.microsoft.com/mssql/server:2019-latest
        env:
        - name: ACCEPT_EULA
          value: "Y"
        - name: SA_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mssql-secret
              key: SA_PASSWORD
        ports:
        - containerPort: 1433
        volumeMounts:
        - name: mssql-data
          mountPath: /var/opt/mssql
      volumes:
      - name: mssql-data
        persistentVolumeClaim:
          claimName: mssql-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: sqlserver
  namespace: mixcore
spec:
  selector:
    app: sqlserver
  ports:
  - port: 1433
    targetPort: 1433
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mssql-pvc
  namespace: mixcore
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

Create the database secret:

kubectl create secret generic mssql-secret \
  --from-literal=SA_PASSWORD="YourStrongPassword" \
  --namespace mixcore

Apply the database configuration:

kubectl apply -f mixcore-db.yaml

3. Mixcore CMS Deployment

Create the Mixcore deployment YAML file mixcore-app.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mixcore
  namespace: mixcore
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mixcore
  template:
    metadata:
      labels:
        app: mixcore
    spec:
      containers:
      - name: mixcore
        image: mixcore/mix.core:latest
        ports:
        - containerPort: 80
        env:
        - name: ASPNETCORE_ENVIRONMENT
          value: Production
        - name: ConnectionStrings__DefaultConnection
          value: "Server=sqlserver;Database=mixcore;User=sa;Password=$(MSSQL_SA_PASSWORD);TrustServerCertificate=true"
        envFrom:
        - secretRef:
            name: mssql-secret
        volumeMounts:
        - name: mixcore-media
          mountPath: /app/wwwroot/media
        - name: appsettings
          mountPath: /app/appsettings.Production.json
          subPath: appsettings.Production.json
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
      volumes:
      - name: mixcore-media
        persistentVolumeClaim:
          claimName: mixcore-media-pvc
      - name: appsettings
        configMap:
          name: mixcore-config
---
apiVersion: v1
kind: Service
metadata:
  name: mixcore
  namespace: mixcore
spec:
  selector:
    app: mixcore
  ports:
  - port: 80
    targetPort: 80
  type: ClusterIP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mixcore-media-pvc
  namespace: mixcore
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi

Create the configuration map for application settings:

kubectl create configmap mixcore-config \
  --from-file=appsettings.Production.json \
  --namespace mixcore

Apply the Mixcore configuration:

kubectl apply -f mixcore-app.yaml

4. Ingress Configuration

Create the Ingress YAML file mixcore-ingress.yaml:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mixcore-ingress
  namespace: mixcore
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  rules:
  - host: mixcore.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: mixcore
            port:
              number: 80
  tls:
  - hosts:
    - mixcore.example.com
    secretName: mixcore-tls-secret

Apply the Ingress configuration:

kubectl apply -f mixcore-ingress.yaml

Helm Chart Deployment

For more automated deployments, you can use Helm:

  1. Create a Helm chart for Mixcore:

    helm create mixcore
  2. Modify the chart templates to match your requirements

  3. Install the Helm chart:

    helm install mixcore ./mixcore --namespace mixcore --create-namespace

Scaling and High Availability

Horizontal Pod Autoscaling

Create mixcore-hpa.yaml:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: mixcore-hpa
  namespace: mixcore
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: mixcore
  minReplicas: 3
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80

Apply the HPA:

kubectl apply -f mixcore-hpa.yaml

Database High Availability

For production environments, consider:

  1. SQL Server Always On Availability Groups
  2. Cloud-managed database services
  3. Database clustering solutions

Monitoring and Logging

Prometheus and Grafana

  1. Install the Prometheus Operator:

    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    helm install prometheus prometheus-community/kube-prometheus-stack \
      --namespace monitoring --create-namespace
  2. Create a ServiceMonitor for Mixcore:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: mixcore-monitor
      namespace: monitoring
    spec:
      selector:
        matchLabels:
          app: mixcore
      endpoints:
      - port: http
        path: /metrics
      namespaceSelector:
        matchNames:
        - mixcore

ELK Stack for Logging

Consider setting up the Elastic Stack (Elasticsearch, Logstash, Kibana) for centralized logging.

Deployment Strategies

Blue-Green Deployment

  1. Deploy a new version alongside the existing one
  2. Test the new version
  3. Switch traffic when ready
  4. Remove the old version

Canary Deployment

Configure traffic splitting in your Ingress controller:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mixcore-canary
  annotations:
    nginx.ingress.kubernetes.io/canary: "true"
    nginx.ingress.kubernetes.io/canary-weight: "20"

Troubleshooting

Common Issues

  1. Pod startup failures:

    kubectl logs -n mixcore deployment/mixcore
    kubectl describe pod -n mixcore [pod-name]
  2. Database connection issues:

    • Verify secrets are correctly created
    • Check network policies allow communication
    • Ensure database service is running
  3. Persistent volume issues:

    • Check storage class availability
    • Verify volume provisioning
    • Check permissions on mounted volumes

Next Steps

Need Help?

Clone this wiki locally