Deploying Dovecot on Kubernetes

Here's a step-by-step guide to deploy Dovecot using Kubernetes manifests:

1. Create a Namespace

apiVersion: v1
kind: Namespace
metadata:
  name: dovecot

Apply the namespace:

kubectl apply -f namespace.yaml

2. Create a ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: dovecot-config
  namespace: dovecot
data:
  dovecot.conf: |
    protocols = imap pop3
    listen = *
    mail_location = maildir:/var/mail/%d/%n
    ssl = yes
    ssl_cert = </etc/ssl/certs/dovecot.pem
    ssl_key = </etc/ssl/private/dovecot.key

3. Create a Persistent Volume Claim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dovecot-mail-pvc
  namespace: dovecot
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

4. Create the Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dovecot
  namespace: dovecot
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dovecot
  template:
    metadata:
      labels:
        app: dovecot
    spec:
      containers:
      - name: dovecot
        image: dovecot/dovecot:latest
        ports:
        - containerPort: 143
          name: imap
        - containerPort: 993
          name: imaps
        volumeMounts:
        - name: dovecot-config
          mountPath: /etc/dovecot
        - name: dovecot-mail
          mountPath: /var/mail
      volumes:
      - name: dovecot-config
        configMap:
          name: dovecot-config
      - name: dovecot-mail
        persistentVolumeClaim:
          claimName: dovecot-mail-pvc

5. Create a Service

apiVersion: v1
kind: Service
metadata:
  name: dovecot
  namespace: dovecot
spec:
  type: LoadBalancer
  ports:
  - port: 143
    targetPort: 31143
    name: imap
  - port: 993
    targetPort: 31993
    name: imaps
  selector:
    app: dovecot

6. Apply the Manifests

Save each manifest in separate YAML files and apply them in order:

kubectl apply -f namespace.yaml
kubectl apply -f configmap.yaml
kubectl apply -f pvc.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

7. Verify the Deployment

kubectl get all -n dovecot
kubectl get pods -n dovecot
kubectl describe deployment dovecot -n dovecot