deployment.yaml 3.12 KB
apiVersion: apps/v1
kind: Deployment
metadata:
  name: inventory-service
  namespace: ecommerce
  labels:
    app: inventory-service
    version: v1.0.0
spec:
  replicas: 2
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: inventory-service
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: inventory-service
        app: microservice
        version: v1.0.0
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8080"
        prometheus.io/path: "/actuator/prometheus"
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - inventory-service
              topologyKey: kubernetes.io/hostname
      containers:
      - name: inventory-service
        image: your-registry/inventory-service:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        - containerPort: 8081
          name: metrics
          protocol: TCP
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: "production"
        - name: MONGO_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-secret
              key: password
        - name: REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: redis-secret
              key: password
        - name: RABBITMQ_PASSWORD
          valueFrom:
            secretKeyRef:
              name: rabbitmq-secret
              key: password
        - name: PRODUCT_SERVICE_URL
          value: "http://product-service:8080"
        - name: ORDER_SERVICE_URL
          value: "http://order-service:8080"
        resources:
          requests:
            memory: "384Mi"
            cpu: "250m"
          limits:
            memory: "768Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /api/inventory/actuator/health/liveness
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 75
          periodSeconds: 30
          timeoutSeconds: 10
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /api/inventory/actuator/health/readiness
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 40
          periodSeconds: 15
          timeoutSeconds: 5
          failureThreshold: 3
        startupProbe:
          httpGet:
            path: /api/inventory/actuator/health/startup
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 40
          periodSeconds: 15
          failureThreshold: 30
        securityContext:
          runAsNonRoot: true
          runAsUser: 1000
          allowPrivilegeEscalation: false
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        fsGroup: 1000
      imagePullSecrets:
      - name: regcred