'load balancer'에 해당하는 글 3건

finalizers

Daily/Prog 2021. 12. 12. 03:17

EKS 에서 ingress 와 loadbalancer 를 생성했는데 pending 상태라 살펴보니 자격증명 실패 에러가 발생했다.

 

$ kubectl describe ingress my-ingress
Warning FailedBuildModel  32m (x9 over 47m)  ingress  (combined from similar events): Failed build model due to WebIdentityErr: failed to retrieve credentials
caused by: InvalidIdentityToken: Incorrect token audience
status code: 400, request id: 4599a6da-7a29-4d82-baf7-d546e7811234

 

확인하고 삭제하려는데 삭제가 안된다.ㅋ 강제 삭제(--force --grace-period=0)도 안된다; 시간이 한참 지나도 프롬프트가 멈춰버림.

 

$ kubectl describe svc my-nlb
...
Normal   DeletedLoadBalancer  40m  service-controller  Deleted load balancer
Warning  FailedDeployModel    38m  service             Failed deploy model due to WebIdentityErr: failed to retrieve credentials
Warning  ClusterIPNotAllocated  75s (x5 over 37m)  ipallocator-repair-controller    Cluster IP [IPv4]:172.20.23.140 is not allocated; repairing
Warning  PortNotAllocated       75s (x5 over 37m)  portallocator-repair-controller  Port 32083 is not allocated; repairing

 

권한은 없는데 복구 의지가 강해서 그런건지, 안죽고 계속 살아나려고 발버둥 치는 느낌. 다른 서비스들과 결합이 되어 있는건지... 클러스터를 거의 초기화 수준으로 다른 모든 리소스를 다 지웠는데도 삭제가 안되는 생명줄 긴 로드 밸런서들. 구글님 덕에 겨우 찾아 삭제했다.

 

$ kubectl patch service/<your_service> --type json --patch='[ { "op": "remove", "path": "/metadata/finalizers" } ]'
$ kubectl patch ingress <your_ingress> -n <your_ns> -p '{"metadata":{"finalizers":[]}}' --type=merge

 

finalizers 는 리소스를 완전히 삭제하기 전에 특정 조건이 충족될 때까지 대기하게 한다. 삭제가 완료되면 대상에서 관련 finalizers 를 삭제하는데, 위처럼 metadata.finalizers 필드를 비워주면 Kubernetes 는 삭제가 완료된 것으로 인식하게 된다.

 


WRITTEN BY
손가락귀신
정신 못차리면, 벌 받는다.

,

aws-alb

 

AWS 로드 밸런서 컨트롤러로부터 생성/관리 되는 로드 밸런서: NLB / ALB

 

NLB(Network Load Balancing)

 

  • 네트워크 트래픽을 OSI 모델의 L4 에서 로드 밸런싱
  • k8s 에서 LoadBalancer 타입의 Service 생성시 프로비저닝됨
  • 초당 수백만 개의 요청 처리 가능
  • 고정 IP 등록 가능
  • IP / Port 지정으로 타겟그룹 등록 가능

 

ALB(Application Load Balancing)

 

  • 어플리케이션 트래픽을 OSI 모델의 L7 에서 로드 밸런싱
  • k8s 에서 ingress 리소스 생성시 프로비저닝됨
  • 여러 도메인, 호스트, 경로 기반의 라우팅 가능
  • 한 URL에서 다른 URL로 요청을 리디렉션 가능

 

NLB / ALB 서브넷 설정

 

  • 방법1. Service 구성시 서브넷 ID 명시
  • 방법2. private/public 서브넷에 태그 설정
    - public : kubernetes.io/cluster/cluster-name : shared, kubernetes.io/role/elb : 1
    - private : kubernetes.io/cluster/cluster-name : shared, kubernetes.io/role/internal-elb : 1

 

 

ALB 구동 테스트

 

ALB 생성 역시 NLB 와 흡사하지만 ingress 리소스를 생성해야 하고, NodePort 나 LoadBalancer 타입의 Service 를 생성하는 것이 다르다. 마찬가지로 nginx 의 첫화면을 확인하는 샘플. 어플리케이션 배포는 NLB 테스트에 사용한 것과 동일, ALB / NodePort 정상 구동 확인하고, 브라우저에서 nginx 확인하고...

 

 

1. Sample namespace

 

$ kubectl create namespace alb-sample-app

& 해당 namespace 로 fargate 프로파일도 작성

 

 

2. nginx Application, NLB 생성

 

로드밸런서의 타입인 Instance 와 IP 중 Fargate 는 IP 타겟만 지정 가능하다. Instance 는 node 로, IP 는 pod 로 라우팅된다. 아래 스크립트는 선택기가 app=nginx 인 pod 로 라우팅하는 ALB 를 생성한다.

 

$ vi sample-alb.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-app
  namespace: alb-sample-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: public.ecr.aws/nginx/nginx:1.21
          ports:
            - name: tcp
              containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  namespace: alb-sample-app
  name: sample-service-nodeport
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: alb-sample-app
  name: sample-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: sample-service-nodeport
                port:
                  number: 80
$ kubectl apply -f sample.yaml
Deployment/sample-app created
Service/sample-service-nodeport created
Ingress/sample-ingress created

 

 

3. 서비스 확인

 

$ kubectl get svc sample-service-nodeport -n alb-sample-app
NAME                      TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
sample-service-nodeport   NodePort   172.20.23.108   <none>        80:31517/TCP   4s

$ kubectl get ingress sample-ingress -n alb-sample-app
NAME             CLASS    HOSTS   ADDRESS                                                               PORTS   AGE
sample-ingress   <none>   *       k8s-samplein-1234d81632-1363801234.ap-northeast-2.elb.amazonaws.com   80      3h43m

 

여기까지 진행하였으면, AWS 관리콘솔에서 [로드밸런서] 와 [대상 그룹] 이 정상적으로 구동되었는지 확인한다.

  • 로드밸런서 : DNS 이름 / application 유형 / internet-facing 체계
  • 대상그룹 : 80 port / HTTP protocal / IP target / Health status

 

 

4. 결과 확인

 

상단 ingress DNS 주소로 curl 이나 browser 를 사용하여 nginx 첫 페이지를 확인한다.

 

$ curl k8s-samplein-1234d81632-1363801234.ap-northeast-2.elb.amazonaws.com

 

nginx

 

* ALB 에서 80 port 접속시 container 의 8080 port 로 라우팅 하려면...

  • Ingress Service port: 80
  • Service port:80, targetPort: 8080
  • Deployment containerPort: 8080

 

* NodePort 가 아닌 LoadBalancer(NLB) 서비스를 사용할 경우, 내부 트래픽만 가능하도록 기존 NLB 생성했던 내용에서 internet-facing 만 삭제. (default: internal)

 

$ vi sample-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nlb-sample-service
  namespace: nlb-sample-app
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: external
    service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
    #service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: LoadBalancer
  selector:
    app: nginx

 

 


WRITTEN BY
손가락귀신
정신 못차리면, 벌 받는다.

,

aws-nlb

 

AWS 로드 밸런서 컨트롤러로부터 생성/관리 되는 로드 밸런서: NLB / ALB

 

NLB(Network Load Balancing)

 

  • 네트워크 트래픽을 OSI 모델의 L4 에서 로드 밸런싱
  • k8s 에서 LoadBalancer 타입의 Service 생성시 프로비저닝됨
  • 초당 수백만 개의 요청 처리 가능
  • 고정 IP 등록 가능
  • IP / Port 지정으로 타겟그룹 등록 가능

 

ALB(Application Load Balancing)

 

  • 어플리케이션 트래픽을 OSI 모델의 L7 에서 로드 밸런싱
  • k8s 에서 ingress 리소스 생성시 프로비저닝됨
  • 여러 도메인, 호스트, 경로 기반의 라우팅 가능
  • 한 URL에서 다른 URL로 요청을 리디렉션 가능

 

NLB / ALB 서브넷 설정

 

  • 방법1. Service 구성시 서브넷 ID 명시
  • 방법2. private/public 서브넷에 태그 설정
    - public : kubernetes.io/cluster/cluster-name : shared, kubernetes.io/role/elb : 1
    - private : kubernetes.io/cluster/cluster-name : shared, kubernetes.io/role/internal-elb : 1

 

 

NLB 구동 테스트

 

NLB 를 사용할 계획은 아니지만 샘플이 간단해서 기록해 본다. NLB 를 통해 nginx 의 첫화면을 확인하는 샘플. 어플리케이션 정상 배포 확인하고, NLB 정상 구동 확인하고, 브라우저에서 nginx 확인하고...

 

 

1. Sample namespace

 

$ kubectl create namespace nlb-sample-app

& 해당 namespace 로 fargate 프로파일도 작성

 

 

2. nginx 어플리케이션 배포

 

$ vi sample-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nlb-sample-app
  namespace: nlb-sample-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: public.ecr.aws/nginx/nginx:1.21
          ports:
            - name: tcp
              containerPort: 80
$ kubectl apply -f sample-deployment.yaml
Deployment/nlb-sample-app created

 

 

3. NLB 생성

 

로드밸런서의 타입인 Instance 와 IP 중 Fargate 는 IP 타겟만 지정 가능하다. Instance 는 node 로, IP 는 pod 로 라우팅된다. 아래 스크립트는 선택기가 app=nginx 인 pod 로 라우팅하는 NLB 를 생성한다.

 

$ vi sample-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nlb-sample-service
  namespace: nlb-sample-app
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: external
    service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
    service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: LoadBalancer
  selector:
    app: nginx
$ kubectl apply -f sample-service.yaml
Service/nlb-sample-service created

 

 

4. 서비스 확인

 

$ kubectl get svc nlb-sample-service -n nlb-sample-app
NAME            TYPE           CLUSTER-IP         EXTERNAL-IP                                                                    PORT(S)        AGE
sample-service  LoadBalancer   10.100.240.137   k8s-nlbsampl-nlbsampl-xxxxxxxxxx-xxxxxxxxxxxxxxxx.elb.us-west-2.amazonaws.com   80:32400/TCP   16h

 

여기까지 진행하였으면, AWS 관리콘솔에서 [로드밸런서] 와 [대상 그룹] 이 정상적으로 구동되었는지 확인한다.

  • 로드밸런서 : DNS 이름 / network 유형 / internet-facing 체계
  • 대상그룹 : 80 port / TCP protocal / IP target / Health status

 

nlb

 

 

5. 결과 확인

 

상단 EXTERNAL-IP 의 DNS 주소로 curl 이나 browser 를 사용하여 nginx 첫 페이지를 확인한다.

 

$ curl k8s-nlbsampl-nlbsampl-xxxxxxxxxx-xxxxxxxxxxxxxxxx.elb.us-west-2.amazonaws.com

 

nginx

 

 

* NLB 에서 80 port 접속시 container 의 8080 port 로 라우팅 하려면...

  • Service port:80, targetPort: 8080
  • Deployment containerPort: 8080

 


WRITTEN BY
손가락귀신
정신 못차리면, 벌 받는다.

,