cat <<EOF> values.yaml
podLabels: {
  skills/dedicated: addon
}
EOF
helm repo add eks <https://aws.github.io/eks-charts>
helm repo update eks
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \\
  -n hrdkorea \\
  --set clusterName=hrdkorea-cluster \\
  --set serviceAccount.create=false \\
  --set serviceAccount.name=aws-load-balancer-controller \\
  -f values.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hrdkorea-ingress
  namespace: hrdkorea
  annotations:
    alb.ingress.kubernetes.io/load-balancer-name: hrdkorea-app-alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    # alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]'
    alb.ingress.kubernetes.io/healthcheck-path: /healthcheck
    alb.ingress.kubernetes.io/healthcheck-interval-seconds: '5'
    alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '3'
    alb.ingress.kubernetes.io/healthy-threshold-count: '3'
    alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
    alb.ingress.kubernetes.io/target-group-attributes: deregistration_delay.timeout_seconds=30
    alb.ingress.kubernetes.io/actions.customer: >
      {"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"customer-service","servicePort":8080}]}}
    alb.ingress.kubernetes.io/actions.order: >
      {"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"order-service","servicePort":8080}]}}
    alb.ingress.kubernetes.io/actions.product: >
      {"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"product-service","servicePort":8080}]}}
    alb.ingress.kubernetes.io/actions.targets: >
      {"type":"forward","forwardConfig":{"targetGroups":[{"serviceName":"customer-service","servicePort":8080,"weight":34},{"serviceName":"order-service","servicePort":8080,"weight":33},{"serviceName":"product-service","servicePort":8080,"weight":33}]}}
    alb.ingress.kubernetes.io/conditions.customer: >
      [{"Field":"query-string","QueryStringConfig":{"Values":[{"Key":"path","Value":"customer"}]}}]
    alb.ingress.kubernetes.io/conditions.order: >
      [{"Field":"query-string","QueryStringConfig":{"Values":[{"Key":"path","Value":"order"}]}}]
    alb.ingress.kubernetes.io/conditions.product: >
      [{"Field":"query-string","QueryStringConfig":{"Values":[{"Key":"path","Value":"product"}]}}]
    alb.ingress.kubernetes.io/actions.response-404: >
        {"type":"fixed-response","fixedResponseConfig":{"contentType":"text/plain","statusCode":"404"}}

spec:
  ingressClassName: alb
  rules:
    - http:
        paths:
          - path: /v1/customer
            pathType: Prefix
            backend:
              service:
                name: customer-service
                port:
                  number: 8080
          - path: /v1/order
            pathType: Prefix
            backend:
              service:
                name: order-service
                port:
                  number: 8080
          - path: /v1/product
            pathType: Prefix
            backend:
              service:
                name: product-service
                port:
                  number: 8080
          - path: /healthcheck
            pathType: ImplementationSpecific
            backend:
              service:
                name: customer
                port:
                  name: use-annotation
          - path: /healthcheck
            pathType: ImplementationSpecific
            backend:
              service:
                name: order
                port:
                  name: use-annotation
          - path: /healthcheck
            pathType: ImplementationSpecific
            backend:
              service:
                name: product
                port:
                  name: use-annotation
  defaultBackend:
    service:
      name: response-404
      port:
        name: use-annotation
#!/bin/bash
public_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=hrdkorea-public-sn-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text)
public_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=hrdkorea-public-sn-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text)
private_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=hrdkorea-private-sn-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text)
private_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=hrdkorea-private-sn-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text)

public_subnet_name=("$public_a" "$public_b")
private_subnet_name=("$private_a" "$private_b")

for name in "${public_subnet_name[@]}"
do
    aws ec2 create-tags --resources $name --tags Key=kubernetes.io/role/elb,Value=1
done

for name in "${private_subnet_name[@]}"
do
    aws ec2 create-tags --resources $name --tags Key=kubernetes.io/role/internal-elb,Value=1
done

kubectl apply -f ingress.yaml