apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-a
  namespace: app
  labels:
    app: service-a
spec:
  replicas: 2
  selector:
    matchLabels:
      app: service-a
  template:
    metadata:
      labels:
        app: service-a
    spec:
      containers:
      - name: service-a-conatiner
        image: IMAGE-A
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          name: http
        volumeMounts:
        - name: log-volume
          mountPath: /log
      - 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: fluent-bit-sidecar-a-config
IMAGE_URL=$(aws ecr describe-repositories --repository-name service --query "repositories[?repositoryName=='service'].repositoryUri" --output text --region ap-northeast-2)
IMAGE_A_TAG=$(aws ecr describe-images --repository-name service --query "imageDetails[?contains(imageTags, 'a')].imageTags" --output text --region ap-northeast-2)
IMAGE_A="$IMAGE_URL:$IMAGE_A_TAG"
sed -i "s|IMAGE-A|$IMAGE_A|g" service-a.yaml
kubectl apply -f service-a.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-b
  namespace: app
  labels:
    app: service-b
spec:
  replicas: 2
  selector:
    matchLabels:
      app: service-b
  template:
    metadata:
      labels:
        app: service-b
    spec:
      containers:
      - name: service-b-conatiner
        image: IMAGE-B
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          name: http
        volumeMounts:
        - name: log-volume
          mountPath: /log
      - 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: fluent-bit-sidecar-b-config
IMAGE_URL=$(aws ecr describe-repositories --repository-name service --query "repositories[?repositoryName=='service'].repositoryUri" --output text --region ap-northeast-2)
IMAGE_B_TAG=$(aws ecr describe-images --repository-name service --query "imageDetails[?contains(imageTags, 'b')].imageTags" --output text --region ap-northeast-2)
IMAGE_B="$IMAGE_URL:$IMAGE_B_TAG"
sed -i "s|IMAGE-B|$IMAGE_B|g" service-b.yaml
kubectl apply -f service-b.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-c
  namespace: app
  labels:
    app: service-c
spec:
  replicas: 2
  selector:
    matchLabels:
      app: service-c
  template:
    metadata:
      labels:
        app: service-c
    spec:
      containers:
      - name: service-c-conatiner
        image: IMAGE-C
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          name: http
        volumeMounts:
        - name: log-volume
          mountPath: /log
      - 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: fluent-bit-sidecar-c-config
IMAGE_URL=$(aws ecr describe-repositories --repository-name service --query "repositories[?repositoryName=='service'].repositoryUri" --output text --region ap-northeast-2)
IMAGE_C_TAG=$(aws ecr describe-images --repository-name service --query "imageDetails[?contains(imageTags, 'c')].imageTags" --output text --region ap-northeast-2)
IMAGE_C="$IMAGE_URL:$IMAGE_C_TAG"