기본 인증을 사용한 Ingress 생성
기본 인증을 사용한 Ingress 생성 (nginx) (Create an Ingress with Basic Authentication (nginx))
Note: 2025년 11월 기준, Kubernetes 프로젝트는 ingress-nginx 컨트롤러의 사용 중지(retirement)를 발표했어요. 자세한 내용은 공식 발표를 참고하세요.
권장 대안: 지속적인 지원과 보안을 위해 다음 방법 중 하나로 Longhorn UI를 노출하는 것을 권장해요.
- Traefik Ingress: 현재 RKE2/K3s 환경의 기본값이에요. Traefik으로 Ingress 생성을 참고하세요.
- Gateway API: 고급 라우팅을 위한 Ingress의 현대적인 후속 표준이에요. Gateway API로 HTTPRoute 생성을 참고하세요.
kubectl이나 Helm으로 Kubernetes 클러스터에 Longhorn을 설치했다면, 외부 트래픽이 Longhorn UI에 도달하도록 Ingress를 생성해야 해요.
kubectl과 Helm 설치에서는 인증이 기본적으로 활성화돼 있지 않아요. 다음 단계에서는 nginx 인그레스 컨트롤러용 어노테이션으로 기본 인증을 사용하는 Ingress를 생성하는 방법을 배워요.
출처: 문서
본문
- 기본 인증 파일
auth를 생성하세요. 생성되는 파일 이름이 정확히auth여야 해요(정확히는 secret이data.auth키를 가져야 해요). 그렇지 않으면 Ingress가 503을 반환해요.
$ USER=; PASSWORD=; echo "${USER}:$(openssl passwd -stdin -apr1 > auth
- secret을 생성하세요.
$ kubectl -n longhorn-system create secret generic basic-auth --from-file=auth
- Ingress 매니페스트
longhorn-ingress.yml을 생성하세요.
v1.2.0부터 Longhorn은 UI에서 backing image 업로드를 지원해요. 그래서 이미지 업로드가 정상 동작하도록 아래처럼 nginx.ingress.kubernetes.io/proxy-body-size: 10000m을 지정하세요.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: longhorn-ingress
namespace: longhorn-system
annotations:
# type of authentication
nginx.ingress.kubernetes.io/auth-type: basic
# prevent the controller from redirecting (308) to HTTPS
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
# name of the secret that contains the user/password definitions
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropriate context why the authentication is required
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required '
# custom max body size for file uploading like backing image uploading
nginx.ingress.kubernetes.io/proxy-body-size: 10000m
spec:
ingressClassName: nginx
rules:
- http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: longhorn-frontend
port:
number: 80
- Ingress를 생성하세요.
$ kubectl -n longhorn-system apply -f longhorn-ingress.yml
e.g.:
$ USER=foo; PASSWORD=bar; echo "${USER}:$(openssl passwd -stdin -apr1 > auth
$ cat auth
foo:$apr1$FnyKCYKb$6IP2C45fZxMcoLwkOwf7k0
$ kubectl -n longhorn-system create secret generic basic-auth --from-file=auth
secret/basic-auth created
$ kubectl -n longhorn-system get secret basic-auth -o yaml
apiVersion: v1
data:
auth: Zm9vOiRhcHIxJEZueUtDWUtiJDZJUDJDNDVmWnhNY29Md2tPd2Y3azAK
kind: Secret
metadata:
creationTimestamp: "2020-05-29T10:10:16Z"
name: basic-auth
namespace: longhorn-system
resourceVersion: "2168509"
selfLink: /api/v1/namespaces/longhorn-system/secrets/basic-auth
uid: 9f66233f-b12f-4204-9c9d-5bcaca794bb7
type: Opaque
$ echo "
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: longhorn-ingress
namespace: longhorn-system
annotations:
# type of authentication
nginx.ingress.kubernetes.io/auth-type: basic
# prevent the controller from redirecting (308) to HTTPS
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
# name of the secret that contains the user/password definitions
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropriate context why the authentication is required
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required '
spec:
rules:
- http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: longhorn-frontend
port:
number: 80
" | kubectl -n longhorn-system create -f -
ingress.networking.k8s.io/longhorn-ingress created
$ kubectl -n longhorn-system get ingress
NAME HOSTS ADDRESS PORTS AGE
longhorn-ingress * 45.79.165.114,66.228.45.37,97.107.142.125 80 2m7s
$ curl -v http://97.107.142.125/
* Trying 97.107.142.125...
* TCP_NODELAY set
* Connected to 97.107.142.125 (97.107.142.125) port 80 (#0)
> GET / HTTP/1.1
> Host: 97.107.142.125
> User-Agent: curl/7.64.1
> Accept: */*
>
401 Authorization Required
401 Authorization Required
openresty/1.15.8.1
* Connection #0 to host 97.107.142.125 left intact
* Closing connection 0
$ curl -v http://97.107.142.125/ -u foo:bar
* Trying 97.107.142.125...
* TCP_NODELAY set
* Connected to 97.107.142.125 (97.107.142.125) port 80 (#0)
* Server auth using Basic with user 'foo'
> GET / HTTP/1.1
> Host: 97.107.142.125
> Authorization: Basic Zm9vOmJhcg==
> User-Agent: curl/7.64.1
> Accept: */*
>
......
AWS EKS Kubernetes 클러스터를 위한 추가 단계 (Additional Steps for AWS EKS Kubernetes Clusters)
nginx Ingress 컨트롤러를 인터넷에 노출하려면 ELB(Elastic Load Balancer)를 생성해야 해요. 추가 비용이 발생할 수 있어요.
-
nginx ingress controller 문서에 따라 사전 필수 리소스를 생성하세요.
-
다음 단계를 따라 ELB를 생성하세요.
참고 자료 (References)
https://kubernetes.github.io/ingress-nginx/