---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nats
  namespace: lifecycle
  labels:
    app: nats
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nats
  template:
    metadata:
      labels:
        app: nats
    spec:
      containers:
      - name: nats
        image: nats:2.10-alpine
        args:
          - "-js"
          - "-sd"
          - "/data"
        ports:
        - name: client
          containerPort: 4222
        - name: http
          containerPort: 8222
        volumeMounts:
        - name: storage
          mountPath: /data
        livenessProbe:
          tcpSocket:
            port: client
          initialDelaySeconds: 10
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /healthz
            port: http
          initialDelaySeconds: 5
          periodSeconds: 5
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
      volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: nats-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: nats
  namespace: lifecycle
spec:
  selector:
    app: nats
  ports:
  - name: client
    port: 4222
    targetPort: 4222
  - name: http
    port: 8222
    targetPort: 8222
  clusterIP: None

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