/
Using Service & Ingress

Using Service & Ingress

여기서 사용되는 예제는 아래 블로그의 예제를 응용하여 적용하였다.
162. [Kubernetes] 1편 : 쿠버네티스 Ingress 개념 및 사용 방법, 온-프레미스 환경에서 Ingress 구축하기

단, 현재의 k8s api 버전 스펙에 맞지 않는 경우가 있고, Nginx-ingress 역시 위 예제에서 사용되는 것과는 차이가 있다.(기본 NodePort 서비스를 생성해준다. 그러므로 3.4.1 절의 내용은 이미 생성되어 있을 것이다.)

그래서 아래 노트 박스에서와 같이 yaml들을 수정/보완하여 적용하였다.

Ingress controller는 Nginx-ingress: https://github.com/snetsystems/K8s-Objects/blob/master/addons/ingress/ingress-nginx/deploy.yaml 사용하며,
나머지 예제는 https://github.com/snetsystems/K8s-Objects/tree/master/tests/ingress 를 사용한다.

위의 예제들을 모두 kubectl apply -f {yaml파일명}을 통하여 생성하고 나면, 아래 명령어를 통해 테스트 할 수 있다.

# 먼저 접속할 포트를 조회. $ kubectl get svc -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-controller NodePort 10.105.61.45 <none> 80:30270/TCP,443:32129/TCP 17d # 아래에서 IP는 자신의 환경에 알맞은 노드 IP를 준다.(nodePort로 서비스를 생성하였기 때문에 모든 k8s 노드 IP를 적용할 수 있다.) $ curl --resolve alicek106.example.com:30270:61.250.122.245 alicek106.example.com:30270/echo-hostname ------------------------ You accessed to path "/" Access Server URL : http://alicek106.example.com:30270/ Container Hostname : hostname-deployment-6b85d566c5-5k8xv Container IP : 10.244.2.74 Original IP with Proxy : 10.244.1.1 Static string : / ------------------------ Flask received HTTP header : X-Scheme: http X-Forwarded-Host: alicek106.example.com:30270 X-Forwarded-Port: 80 Host: alicek106.example.com:30270 Accept: */* User-Agent: curl/7.29.0 X-Real-Ip: 10.244.1.1 X-Request-Id: 12503ada71646380531be573f5cfdc3e X-Forwarded-For: 10.244.1.1 X-Forwarded-Proto: http remote_addr : 10.244.2.1 ------------------------ # 존재하지 않는 endpoint로 접속할 경우, default http backend로 접속된다. $ curl --resolve alicek106.example.com:30270:61.250.122.245 alicek106.example.com:30270/test default backend - 404

이 외 개념 및 원리 설명은 원본 블로그에 잘 설명되어 있으니, 비교 참조하여 보면 도움이 될 것이다.

5-ingress-svc-externalip.yaml를 적용하면, 아래와 같이 호출할 수 있다.

# 먼저 접속할 포트를 조회. $ kubectl get svc -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-controller ClusterIP 10.107.174.150 10.20.2.217,10.20.2.218 80/TCP 38s $ curl --resolve alicek106.example.com:80:10.20.2.217 alicek106.example.com:80/echo-hostname ------------------------ You accessed to path "/" Access Server URL : http://alicek106.example.com/ Container Hostname : hostname-deployment-6b85d566c5-79dqp Container IP : 10.244.2.27 Original IP with Proxy : 10.244.2.1 Static string : / ------------------------ Flask received HTTP header : X-Forwarded-Host: alicek106.example.com X-Request-Id: bf262fc2c39e9715aa3a304392e055f1 Host: alicek106.example.com X-Real-Ip: 10.244.2.1 X-Forwarded-For: 10.244.2.1 Accept: */* X-Forwarded-Port: 80 X-Scheme: http User-Agent: curl/7.29.0 X-Forwarded-Proto: http remote_addr : 10.244.2.1 ------------------------ $ curl --resolve alicek106.example.com:80:10.20.2.218 alicek106.example.com:80/echo-hostname ------------------------ You accessed to path "/" Access Server URL : http://alicek106.example.com/ Container Hostname : hostname-deployment-6b85d566c5-r2s5l Container IP : 10.244.1.25 Original IP with Proxy : 10.244.2.1 Static string : / ------------------------ Flask received HTTP header : Host: alicek106.example.com X-Forwarded-For: 10.244.2.1 X-Forwarded-Port: 80 User-Agent: curl/7.29.0 Accept: */* X-Real-Ip: 10.244.2.1 X-Forwarded-Proto: http X-Scheme: http X-Forwarded-Host: alicek106.example.com X-Request-Id: e040f08ebb0d6d0953edc848e0f8246a remote_addr : 10.244.1.1 ------------------------

 

Related content

[Certain Version] Installation for test Env.
[Certain Version] Installation for test Env.
More like this
Service Discovery
Service Discovery
More like this
Setting up K8s Metrics Server Addon
Setting up K8s Metrics Server Addon
More like this
Quickstart Helm
Quickstart Helm
Read with this
특정 measurement의 tag key name 변경
특정 measurement의 tag key name 변경
More like this
CloudHub Deploy onto K8s(작성중)
CloudHub Deploy onto K8s(작성중)
Read with this