# Sample YAML File: Kubernetes Deployment
# Provided by Sample-Files.com
# Multi-resource manifest with Deployment, Service, ConfigMap, and Ingress

apiVersion: v1
kind: ConfigMap
metadata:
  name: sampleapp-config
  namespace: production
  labels:
    app: sampleapp
    env: production
data:
  APP_ENV: production
  APP_PORT: "8080"
  LOG_LEVEL: info
  DB_HOST: postgres-service.production.svc.cluster.local
  DB_PORT: "5432"
  DB_NAME: sampleapp
  REDIS_HOST: redis-service.production.svc.cluster.local
  REDIS_PORT: "6379"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sampleapp
  namespace: production
  labels:
    app: sampleapp
    env: production
    version: v3.2.1
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sampleapp
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: sampleapp
        env: production
        version: v3.2.1
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9090"
    spec:
      terminationGracePeriodSeconds: 30
      containers:
        - name: sampleapp
          image: registry.example.com/sampleapp:3.2.1
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8080
            - name: metrics
              containerPort: 9090
          envFrom:
            - configMapRef:
                name: sampleapp-config
          env:
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: sampleapp-secrets
                  key: db-password
          resources:
            requests:
              cpu: 250m
              memory: 256Mi
            limits:
              cpu: "1"
              memory: 512Mi
          livenessProbe:
            httpGet:
              path: /health/live
              port: http
            initialDelaySeconds: 15
            periodSeconds: 20
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health/ready
              port: http
            initialDelaySeconds: 10
            periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: sampleapp-service
  namespace: production
spec:
  type: ClusterIP
  selector:
    app: sampleapp
  ports:
    - name: http
      port: 80
      targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sampleapp-ingress
  namespace: production
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - app.example.com
      secretName: sampleapp-tls
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: sampleapp-service
                port:
                  name: http
