apiVersion: apps/v1
kind: Deployment
metadata:
  name: java-guestbook-backend
  labels:
    app: java-guestbook
    tier: backend
spec:
  replicas: 5
  selector:
    matchLabels:
      app: java-guestbook
      tier: backend
  template:
    metadata:
      labels:
        app: java-guestbook
        tier: backend
    spec:
      initContainers:
      - name: init-db-ready
        image: mongo:4
        command: ['/bin/sh', '-c']
        args:
          - echo "Waiting for mongodb at java-guestbook-mongodb:27017 to go live before the BE..."; 
          - until (mongo --host java-guestbook-mongodb:27017 >/dev/null) do echo "Waiting for connection for 2 sec."; sleep 2; done
      containers:
      - name: backend
        image: rishikeshr/java-guestbook-backend
        ports:
        - name: http-server
          containerPort: 8080
        env:
        - name: PORT
          value: "8080"
        - name: GUESTBOOK_DB_ADDR
          value: "java-guestbook-mongodb:27017"
        - name: JAVA_TOOL_OPTIONS
          value: -agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=n,quiet=y
        - name: APPDYNAMICS_NETVIZ_AGENT_HOST
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        - name: APPDYNAMICS_NETVIZ_AGENT_PORT
          value: "3892"
        resources:
          requests:
            cpu: 200m
            memory: 300Mi
          limits:
            cpu: 300m
            memory: 400Mi
