apiVersion: apps/v1
kind: Deployment
metadata:
  name: customer
  namespace: wsi
  labels:
    app: customer
spec:
  replicas: 2
  selector:
    matchLabels:
      app: customer
  template:
    metadata:
      labels:
        app: customer
    spec:
      containers:
      - name: customer-cnt
        image: IMAGE
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: log-volume
          mountPath: /log
        env:
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: customer-credentials
              key: MYSQL_USER
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: customer-credentials
              key: MYSQL_PASSWORD
        - name: MYSQL_HOST
          valueFrom:
            secretKeyRef:
              name: customer-credentials
              key: MYSQL_HOST
        - name: MYSQL_PORT
          valueFrom:
            secretKeyRef:
              name: customer-credentials
              key: MYSQL_PORT
        - name: MYSQL_DBNAME
          valueFrom:
            secretKeyRef:
              name: customer-credentials
              key: MYSQL_DBNAME
      - name: fluent-bit-cnt
        image: fluent/fluent-bit:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 2020
          name: metrics
          protocol: TCP
        volumeMounts:
        - name: config-volume
          mountPath: /fluent-bit/etc/
        - name: log-volume
          mountPath: /log
      volumes:
      - name: log-volume
        emptyDir: {}
      - name: config-volume
        configMap:
          name: customer
      nodeSelector:
        type: app
IMAGE_URL=$(aws ecr describe-repositories --repository-name customer-ecr --query "repositories[].repositoryUri" --output text)
IMAGE_TAG=$(aws ecr describe-images --repository-name customer-ecr --query "imageDetails[].imageTags" --output text)
IMAGE="$IMAGE_URL:$IMAGE_TAG"
sed -i "s|IMAGE|$IMAGE|g" deployment.yaml
kubectl apply -f deployment.yaml
apiVersion: v1
kind: Service
metadata:
  name: customer-service
  namespace: wsi
spec:
  selector:
    app: customer
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
kubectl apply -f service.yaml