AWS Load Balancer Controller 사용 중 Ingress 오류 api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1
AWS LoadBalancer Controller 사용 중 Ingress에서 api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1 오류가 발생하는 원인과 해결 방법에 대해 설명하니다.
오류
AWS LoadBalancer Controller를 사용하는 중 Ingress에서 다음과 같은 오류가 발생하며 대상 그룹 생성이나 업데이트가 실패할 때가 있습니다.
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedDeployModel 3m14s ingress Failed deploy model due to operation error Elastic Load Balancing v2: CreateTargetGroup, https response error StatusCode: 400, RequestID: 12345678-9abc-defg-hijk-lmnopqrstuvwxyz, api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1 Warning FailedDeployModel 3m14s ingress Failed deploy model due to operation error Elastic Load Balancing v2: CreateTargetGroup, https response error StatusCode: 400, RequestID: 12345678-9abc-defg-hijk-lmnopqrstuvwxyz, api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1 Warning FailedDeployModel 3m13s ingress Failed deploy model due to operation error Elastic Load Balancing v2: CreateTargetGroup, https response error StatusCode: 400, RequestID: 12345678-9abc-defg-hijk-lmnopqrstuvwxyz, api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1
이는 AWS LoadBalancer Controller에서 사용하는 Ingress Annotations 중 alb.ingress.kubernetes.io/target-type의 설정과 Service 타입이 맞지 않기 때문입니다.
alb.ingress.kubernetes.io/target-type
Annotation alb.ingress.kubernetes.io/target-type는 파드로 어떻게 트래픽을 전달할지에 대한 설정이며 instance와 ip 둘 중 한 개를 선택할 수 있으며, 기본 값은 instance입니다.
- instance
- 인스턴스 모드는 NodePort를 통해 클러스터 내의 EC2 인스턴스로 트래픽을 라우팅 합니다.
- 해당 모드를 사용할 때 Service의 타입은 NodePort 혹은 LoadBalancer여야 합니다.
- ip
- IP 모드는 트래픽을 파드의 IP로 직접 라우팅합니다.
- 단, 이를 위해서는 VPC CNI를 사용하여 파드 IP에 대해 ENI의 보조 IP 주소를 사용해야합니다.
- ALB에서 고정 세션을 사용하기 위해서는 IP 모드가 필요합니다. 또한, IP 모드를 사용할 때는 Service의 타입이 중요하지 않습니다.
- IP 모드는 트래픽을 파드의 IP로 직접 라우팅합니다.
만약에 Ingress에서 alb.ingress.kubernetes.io/target-type값을 instance로 설정하였으나 Service의 타입은 ClusterIP로 설정했을 경우 이러한 오류가 발생하게 됩니다. 또한, alb.ingress.kubernetes.io/target-type 값을 설정하지 않을 경우에도 기본 값이 instance이기 때문에 오류가 발생하게 됩니다.
이러한 예시는 다음과 같습니다.
예시
--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: nginx-ingress annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: instance # 혹은 설정하지 않음 spec: ingressClassName: alb rules: - http: paths: - path: / pathType: Prefix backend: service: name: nginx-svc port: number: 80 --- apiVersion: v1 kind: Service metadata: name: nginx-svc spec: selector: app: nginx ports: - protocol: TCP name: http port: 80 targetPort: nginx-http type: ClusterIP
상기의 두 Yaml을 배포할 경우 다음과 같은 오류가 발생합니다.
Name: nginx-ingress Labels: <none> Namespace: default Address: Ingress Class: alb Default backend: <default> Rules: Host Path Backends ---- ---- -------- * / nginx-svc:80 (10.0.156.165:80,10.0.157.225:80) Annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: instance Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedDeployModel 3m14s ingress Failed deploy model due to operation error Elastic Load Balancing v2: CreateTargetGroup, https response error StatusCode: 400, RequestID: 12345678-9abc-defg-hijk-lmnopqrstuvwxyz, api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1 Warning FailedDeployModel 3m14s ingress Failed deploy model due to operation error Elastic Load Balancing v2: CreateTargetGroup, https response error StatusCode: 400, RequestID: 12345678-9abc-defg-hijk-lmnopqrstuvwxyz, api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1 Warning FailedDeployModel 3m13s ingress Failed deploy model due to operation error Elastic Load Balancing v2: CreateTargetGroup, https response error StatusCode: 400, RequestID: 12345678-9abc-defg-hijk-lmnopqrstuvwxyz, api error ValidationError: 1 validation error detected: Value '0' at 'port' failed to satisfy constraint: Member must have value greater than or equal to 1
이후 alb.ingress.kubernetes.io/target-type의 값을 ip로 바꾸거나 Service의 타입을 NodePort 혹은 LoadBalancer로 변경할 경우 정상적으로 동작합니다.
IngressGroup
Ingress Annotation alb.ingress.kubernetes.io/target-type과 Service의 타입을 알맞게 설정하였음에도 이러한 오류가 발생한다면, Ingress Group에 포함된 다른 Ingress에서 Service 타입간의 불일치가 있는지 확인해봐야합니다.
IngressGroup은 하나의 ALB로 여러 Ingress를 지원하는 기능입니다. 기본적으로 Ingress당 1개의 ALB가 생성되지만, IngressGroup을 사용하여 하나의 그룹으로 묶으면 여러 Ingress를 하나의 ALB로 관리할 수 있습니다. 이 때, IngressGroup으로 묶여 있는 여러 Ingress 중 한 개의 Ingress만이라도 alb.ingress.kubernetes.io/target-type과 Service의 타입 간 불일치가 있으면 같은 IngressGroup 내의 모든 Ingress들에서 이러한 오류가 발생합니다. 이를 해결하기 위해서는 불일치가 있는 Ingress와 Service를 찾아 설정 간 불일치를 해결해주면 됩니다.
- Argomenti
- Container
- Lingua
- 한국어
