LoginSignup
2
1

More than 1 year has passed since last update.

EKSでNLBを使ってIPアドレスを制限しつつ外部公開する

Last updated at Posted at 2021-06-01

構成

  • EKS v1.19
  • aws loadbaranser controller v2.2.0
  • externaldns v0.7.6

ポイント

  • spec.loadBalancerSourceRangesで指定したIPアドレスのみを許可する
    • aws loadbaranser controllerのannotationで同じような挙動をすると思われるservice.beta.kubernetes.io/load-balancer-source-ranges:があるけれど、公式ページでspec.loadBalancerSourceRangesを使ってくれとあった
    • NODEに自動アタッチされているSecurityGroupに自動的にルールがエントリされる
  • NLBの場合、ALB ingressとは異なり、Service内でLoadbaranserとそこからルーティングされるNodePortServiceの2つの意味を一緒に定義することになる
    • 通信の流れは、NLB(80)→NodePortService(30082)→CotainerPort(30082)→コンテナ内のNginx(80)という感じだと思う
    • NodePortを指定せず、TargetPortだけでやっていたからか、その場合spec.loadBalancerSourceRangesが作用しなかった
  • ELBを使うにあたりaws loadbaranser controllerが必要だったかはどうだったけかな。。。いらないかも

マニフェストファイル

nginx-replicaset.yaml
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-replicaset-nlb
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-nlb
  template:
    metadata:
      labels:
        app: nginx-nlb
    spec:
      containers:
        - name: nginx-container
          image: nginx:1.12
          ports:
            - containerPort: 30082
---
apiVersion: v1
kind: Service
metadata:
  name: aws-nlb
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: external
    service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance
    service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
    service.beta.kubernetes.io/aws-load-balancer-name: vamdemic-nlb
    external-dns.alpha.kubernetes.io/hostname: nginx.vamdemicsystem.com
spec:
  type: LoadBalancer
  ports:
    - name: "http-port"
      protocol: "TCP"
      port: 80
      targetPort: 80
      nodePort: 30082
  selector:
    app: nginx-nlb
  loadBalancerSourceRanges:
  - "12.34.56.78/32"
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1