클라우드/쿠버네티스

[Kubernetes] 16. 쿠버네티스 Ingress 인그레스

윤창이 2023. 4. 23. 16:00
728x90

 

[주의] 개인 공부를 위해 쓴 글이기 때문에 주관적인 내용은 물론, 쓰여진 정보가 틀린 것일 수도 있습니다!

피드백 부탁드립니다. (- -)(_ _) 꾸벅


[ Ingress란? ]

 


[ Ingress 실습 ]

Question 1 : Application Service 운영

TASK :
ingress-nginx namespace 에 nginx 이미지를 app=nginx 레이블을 가지고 실행하는 nginx pod를 구성하세요.
앞서 생성한 nginx Pod를 서비스 하는 nginx service를 생성하시오 현재 appjs-service 이름의 Service는 이미 동작중입니다. 별도 구성이 필요 없습니다.

 

Question 2 : Ingress 구성

TASK :
app-ingress.yaml 파일을 생성하여 다움 조건의 ingress 서비스를 구성하시오.

  • ingress name : app-ingress
  • NODE_PORT:30080/ 접속 했을때 nginx 서비스로 연결
  • NODE_PORT:30080/app 접속 했을때 appjs-service 서비스로 연결
  • Ingress 구성에 다음의 annotations을 포함 시키시오.
    annotatons: kubernetes.io/ingress.class:nginx


Question 1

yoon@master:~$ kubectl run nginx --image=nginx --labels="app=nginx" -n ingress-nginx
pod/nginx created

yoon@master:~$ kubectl expose pod nginx --port=80 --target-port=80 -n ingress-nginx
service/nginx exposed

yoon@master:~$ kubectl edit svc nginx -n ingress-nginx
service/nginx edited

yoon@master:~$ kubectl get svc -n ingress-nginx
NAME    TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
nginx   NodePort   10.96.61.253   <none>        80:30080/TCP   19m

 

Question 2

$ vi app-ingress.yaml    # ingress 예제에서 문제에 맞게 수정

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: ingress-nginx
  name: app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80
      - path: /app
        pathType: Prefix
        backend:
          service:
            name: appjs
            port:
              number: 80
              
$ kubectl apply -f  app-ingress.yaml
yoon@master:~$ curl 10.96.61.253/    # / 경로로 접속 시 정상적으로 nginx 페이지가 뜸
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>


yoon@master:~$ curl 10.96.61.253/app    # /app 경로로 접속 시 서비스 생성 안 해줘서 에러
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.23.4</center>
</body>
</html>

 

728x90