Search

Ingress

Service type은 아니지만 Service 앞에서 Smart router 및 entry point역할을 하는 오브젝트
외부에서 접근 가능한 URL, Load Balancing, SSL Termination 등을 통해 Service에 대한 HTTP기반 접근을 제공
클러스터에 하나 이상의 실행중인 Ingress Controller가 필요 (e.g. aws-lb-controller, nginx ingress)
ingress.yaml
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: <Ingress Name> namespace: <Namespace> annotations: alb.ingress.kubernetes.io/load-balancer-name: <ALB Name> 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: <Path> 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 spec: ingressClassName: alb rules: - http: paths: - path: / pathType: Prefix backend: service: name: <Service Name> port: number: 80
YAML
복사
type이 인스턴스 인 경우 서비스의 타입을 NodePort로 지정해줘야 한다.
Ingress 두 개 단일 alb로 라우팅하는 방법
alb ingress group을 이용가능하다.
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: a-nginx-ingress annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: ip alb.ingress.kubernetes.io/group.name: app-group spec: ingressClassName: alb rules: - http: paths: - path: / pathType: Prefix backend: service: name: a-nginx-service port: number: 80
YAML
복사
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: b-nginx-ingress annotations: alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: ip alb.ingress.kubernetes.io/group.name: app-group spec: ingressClassName: alb rules: - http: paths: - path: / pathType: Prefix backend: service: name: b-nginx-service port: number: 80
YAML
복사
Install ALB Controller on 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_CLUSTER_NAME \ --set serviceAccount.create=false \ --set serviceAccount.name=aws-load-balancer-controller
Shell
복사
Install ALB Controller on helm with use Values
cat <<EOF> values.yaml nodeSelector: { eks.amazonaws.com/nodegroup: <EKS Node Group Name> } EOF
Shell
복사
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=<cluster name> \ --set serviceAccount.create=false \ --set serviceAccount.name=aws-load-balancer-controller \ -f values.yaml
Shell
복사
Install ALB Controller in Fargate
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_CLUSTER_NAME \ --set serviceAccount.create=false \ --set serviceAccount.name=aws-load-balancer-controller \ --set vpcId=<VPC_ID>
Shell
복사
kubectl patch deployment aws-load-balancer-controller -n kube-system \ --type=json -p='[{"op": "add", "path": "/spec/template/metadata/annotations/eks.amazonaws.com~1fargate-profile", "value":"kube-system"}]' kubectl rollout restart deployment aws-load-balancer-controller -n kube-system
Shell
복사
kubectl apply -f ingress.yaml
Shell
복사
pathType
pathType의 옵션으로는 3가지가 있다
1.
Exact: 경로가 정확히 일치해야 한다.
2.
Prefix: 경로가 지정된 접두사로 시작해야 한다.
3.
ImplementationSpecific: Ingress 컨트롤러에 따라 다르게 동작한다.
1.
Exact:
경로가 정확히 일치해야 합니다.
예를 들어, /foo 경로는 /foo와 일치하지만 /foo/bar와는 일치하지 않습니다.
2.
Prefix:
경로가 지정된 접두사로 시작해야 합니다.
예를 들어, /foo 경로는 /foo와 /foo/bar 모두와 일치합니다.
3.
ImplementationSpecific:
Ingress 컨트롤러에 따라 다르게 동작합니다.
각 Ingress 컨트롤러는 이 값을 해석하는 방법을 정의할 수 있습니다.
Ingress (서브넷 Tag 지정해주기)
public subnet 키 : kubernetes.io/role/elb && 값 : 1
private subnet 키 : kubernetes.io/role/internal-elb && 값 : 1
#!/bin/bash public_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=dev-public-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) public_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=dev-public-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) public_c=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=dev-public-c" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) private_a=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=dev-private-a" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) private_b=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=dev-private-b" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) private_c=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=dev-private-c" --query "Subnets[].SubnetId[]" --region ap-northeast-2 --output text) public_subnet_name=("$public_a" "$public_b" "$public_c") private_subnet_name=("$private_a" "$private_b" "$private_c") 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
Shell
복사