Skip to content

Instantly share code, notes, and snippets.

@juner417
Created July 11, 2023 16:40
Show Gist options
  • Select an option

  • Save juner417/12da2fb46fb43c2139a3aaef0eb927a5 to your computer and use it in GitHub Desktop.

Select an option

Save juner417/12da2fb46fb43c2139a3aaef0eb927a5 to your computer and use it in GitHub Desktop.
aws-lb-controller-example.md

aws lb controller

iam 정책 추가.

curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.4.7/docs/install/iam_policy.json


aws iam create-policy \
    --policy-name AWSLoadBalancerControllerIAMPolicy \
    --policy-document file://iam_policy.json
# 역할을 만들고 그 역할을 service account에 적용함
eksctl utils associate-iam-oidc-provider --region=ap-northeast-2 \
  --cluster=eks-pp --approve

# policy 적용
# eksctl을 이용하면 cloudformation을 이용하여
eksctl create iamserviceaccount \
  --cluster=eks-pp \
  --namespace=kube-system \
  --name=aws-load-balancer-controller \
  --role-name gonz-eks-pp-lb-controller-sa-role \
  --attach-policy-arn=arn:aws:iam::911111111111:policy/AWSLoadBalancerControllerIAMPolicy \
  --approve

aws lb controller 배포

# helm 으로 배포
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 kube-system \
  --set clusterName=eks-pp \
  --set serviceAccount.create=false \
  --set serviceAccount.name=aws-load-balancer-controller

# manifest 확인
helm get manifest -n kube-system aws-load-balancer-controller

eks에서 서비스를 외부에 노출하기 위해서 어떤 방법들을 이용하는가?

  • aws lb controller
  • 두개의 컨트롤러로 구성되어 있고, ingress resource는 alb로, service resource는 nlb로 프로비저닝 한다.

lb controller - svc resource

ingress controller - ing resource

configuration

  • ingress resource class 지정함
# lb controller spec...
spec:
  containers:
  - args:
    - --ingress-class=alb

---
# ingress resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: echoserver
  namespace: echoserver
spec:
  ingressClassName: alb
  ...
  • 특정 namespace 지정가능(지정외 namespace의 리소스는 watch 안함)
spec:
  containers:
  - args:
    - --watch-namespace=default
  • controller command line flag
    • --cluster-name은 배포된 클러스터명과 동일해야 함, 다를경우 subnet auto-discovery가 안됨

subnet auto discovery

  • aws lb controller는 기본적으로 alb, nlb에 대한 네트워크 서브넷을 자동으로 검색함
  • alb는 az가 최소 2개의 subnet이 필요하고, nlb는 1개의 subnet이 필요함
  • 자동검색이 작동하려면 subnet에 tag를 지정해야 함
  • 컨트롤러는 각 az에서 하나의 subnet을 선택함, 자동 검색중 컨트롤러는 subnet에 ip 주소가 8개 이상인 것을 고려한다.
  • az에 정규화된 태그가 지정된 subnet이 여러개 있는 경우, 컨트롤러는 subnet id에 사전순으로 첫번쨰 subnet을 선택함
  • 동일한 VPC에서 여러 클러스터를 실행 중이거나 AWS 서비스가 VPC에서 서브넷을 공유하는 경우 로드 밸런서가 클러스터별로 프로비저닝되는 위치를 보다 효과적으로 제어하려면 서브넷에 태깅할 수 있다.
    • key: kubernetes.io/cluster/my-cluster value: shared or owned
  • 서브넷 ID를 서비스 객체에 대한 주석으로 명시적으로 지정하면 Kubernetes 및 AWS Load Balancer Controller는 이러한 서브넷을 직접 사용하여 로드 밸런서를 생성함.
    • service.beta.kubernetes.io/aws-load-balancer-subnets: subnet-07fa2172d0221e7cf
  • private subnet tag
    • kubernetes.io/role/elb: 1 or ''
  • public subnet tag
    • kubernetes.io/role/internal-elb: 1 or ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment