버전 비교

  • 이 줄이 추가되었습니다.
  • 이 줄이 삭제되었습니다.
  • 서식이 변경되었습니다.

...

코드 블럭
[root@m-k8s vagrant]# k get ing
NAME      CLASS    HOSTS         ADDRESS          PORTS   AGE
ingress   nginx   a.com,b.com    172192.20168.2001.101150     80      5m23s

(10) 클러스터 외부에서 host파일을 변조하여 a.com과 b.com의 주소를 LB external ip로 지정한 후 접속을 시도하여 L7 기반의 로드밸런싱+라우팅이 제대로 작동되는지 확인 합니다.

...

코드 블럭
cat /etc/hosts |grep com
192.168.1.101150 a.com
192.168.1.101150 b.com

  • 이제 노트북에서 a.com와 b.com을 호출 합니다/

코드 블럭
$curl$ curl a.com
Request served Hostname:by nginx1-deployment-545749bf4d98c84c874-h7qfxhfb7t

PodGET Information:
/ HTTP/1.1

Host: a.com
Accept: */*
User-Agent: curl/8.7.1
X-no pod information available-

Server values:
        server_version=nginx: 1.13.3 - lua: 10008

Request Information:
        client_address=10.233.235.153
        method=GET
        real path=/
        query=
        request_version=1.1
        request_uri=http://a.com:8080/

Request Headers:
        accept=*/*
        host=a.com
        user-agent=curl/7.71.1
        x-forwarded-for=192.168.9.237
        x-forwarded-host=a.comForwarded-For: 192.168.1.1
X-Forwarded-Host: a.com
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Scheme: http
X-Real-Ip: 192.168.1.1
X-Request-Id: 36bbde3cd8e429b0139f6cb71041e293
X-Scheme: http

$ curl b.com
Request served by nginx2-deployment-6cb7564d4f-5gkph

GET / HTTP/1.1

Host: b.com
Accept: */*
User-Agent: curl/8.7.1
X-Forwarded-For: 192.168.1.1
X-Forwarded-Host: b.com
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Scheme: http
X-Real-Ip: 192.168.1.1
X-Request-Id: ef73f4cc0d95cb6ea3678abdae8eceec
X-Scheme: http

  • nginx ip로 직접 호출을 해봅니다

    • 레이어상 도메인정보가 없으므로 분기되지 않고 404 페이지가 나타 납니다.

코드 블럭
curl 192.168.1.150
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

  • ingress 설정 시 아래와 같이 서브도메인으로 분기도 가능하므로 활용하도록 합니다

6/08-ingress2.yaml

코드 블럭
languageyaml
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress2
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: a.com
    http:
      paths:
      -  x-forwarded-port=80pathType: Prefix
        x-forwarded-proto=http
path: /a
       x-real-ip=192.168.9.237  backend:
      x-request-id=6b0169dcff0fd35fa780b600967dffb1    service:
    x-scheme=http  Request Body:     name: nginx-service-clusterip
  -no body in request-  $ curl b.com   Hostnameport:
 nginx2-deployment-56d6f87fc9-9m7h2  Pod Information:         -no pod information available-

Server values:
   number: 80
     server_version=nginx: 1.13.3 - luapathType: 10008Prefix
 Request Information:      path: /b
 client_address=10.233.235.153       backend:
 method=GET         realservice:
path=/         query=   name: nginx2-service-clusterip
    request_version=1.1         request_uri=http://b.com:8080/port:
 Request Headers:         accept=*/*   number: 80

코드 블럭
kubectl apply 

...

  • nginx ip로 직접 호출을 해봅니다

    • 레이어상 도메인정보가 없으므로 분기되지 않고 404 페이지가 나타 납니다.

코드 블럭
curl 172.20.200.101
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
  • ingress 설정 시 아래와 같이 서브도메인으로 분기도 가능하므로 활용하도록 합니다

009.ing2.yaml

코드 블럭
languageyaml
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress2
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: a.com
    http:
      paths:
      - pathType: Prefix
        path: /a
        backend:
          service:
            name: nginx-service-clusterip
            port:
              number: 80
      - pathType: Prefix
        path: /b
        backend:
          service:
            name: nginx2-service-clusterip
            port:
              number: 80

코드 블럭
kubectl apply -f 009.ing2.yaml

  • 위와같이 설정한다면 a.com/a 로 들어온 패킷은 nginx-service-clusterip로 라우팅 됩니다.

  • a.com/b 로 들어온 패킷은 nginx2.service-clusterip로 라우팅 됩니다

코드 블럭
curl a.com/a


Hostname: nginx1-deployment-545749bf4d-mgnt8

Pod Information:
        -no pod information available-

Server values:
        server_version=nginx: 1.13.3 - lua: 10008

Request Information:
        client_address=10.233.228.72
        method=GET
        real path=/a
        query=
        request_version=1.1
        request_uri=http://a.com:8080/a

Request Headers:
        accept=*/*
        host=a.com
        user-agent=curl/7.71.1
        x-forwarded-for=192.168.9.38
        x-forwarded-host=a.com
        x-forwarded-port=80
        x-forwarded-proto=http
        x-real-ip=192.168.9.38
        x-request-id=6c98f42fba35104849f57ce30a57b2c3
        x-scheme=http

Request Body:
        -no body in request-

curl a.com/b


Hostname: nginx2-deployment-56d6f87fc9-55gsg

Pod Information:
        -no pod information available-

Server values:
        server_version=nginx: 1.13.3 - lua: 10008

Request Information:
        client_address=10.233.228.72
        method=GET
        real path=/b
        query=
        request_version=1.1
        request_uri=http://a.com:8080/b

Request Headers:
        accept=*/*
        host=a.com
        user-agent=curl/7.71.1
        x-forwarded-for=192.168.9.38
        x-forwarded-host=a.com
        x-forwarded-port=80
        x-forwarded-proto=http
        x-real-ip=192.168.9.38
        x-request-id=b5c8a4dfef21d5acc50763232a7f02c1
        x-scheme=http

Request Body:
        -no body in request-
  • ingress의 기능은 msa아키텍처에 많은 도움을 줄 수 있습니다

  • ingress를 잘 활용 하면 웹서버에 페이지 별로 다른 deploy나 pod그룹을 이용하여 효율적으로 자원을 분배하고 서비스를 배치 하여 관리 할 수 있습니다

...

-f 08-ingress2.yaml

  • 위와같이 설정한다면 a.com/a 로 들어온 패킷은 nginx-service-clusterip로 라우팅 됩니다.

  • a.com/b 로 들어온 패킷은 nginx2.service-clusterip로 라우팅 됩니다

코드 블럭
$ curl a.com/a
Request served by nginx1-deployment-98c84c874-hfb7t

GET /a HTTP/1.1

Host: a.com
Accept: */*
User-Agent: curl/8.7.1
X-Forwarded-For: 192.168.1.1
X-Forwarded-Host: a.com
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Scheme: http
X-Real-Ip: 192.168.1.1
X-Request-Id: 72079ecd9d108f28bc735853731298f8
X-Scheme: http

$ curl a.com/b
Request served by nginx2-deployment-6cb7564d4f-5gkph

GET /b HTTP/1.1

Host: a.com
Accept: */*
User-Agent: curl/8.7.1
X-Forwarded-For: 192.168.1.1
X-Forwarded-Host: a.com
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Scheme: http
X-Real-Ip: 192.168.1.1
X-Request-Id: d7ee6e9f70b8caa258e727fb1fa942ee
X-Scheme: http

  • ingress의 기능은 MSA 아키텍처에 많은 도움을 줄 수 있습니다

  • ingress를 잘 활용 하면 웹서버에 페이지 별로 다른 deploy나 pod그룹을 이용하여 효율적으로 자원을 분배하고 서비스를 배치 하여 관리 할 수 있습니다

정보

ingress의 기능은 msa아키텍처에 많은 도움을 줄 수 있으며, 웹서버에 페이지 별로 다른 deploy나 pod그룹을 이용하여 효율적으로 자원을 분배하고 서비스를 배치 하여 관리 할 수 있습니다.

다음 실습을 위해서 pod를 정리합니다.

코드 블럭
# k delete -f 08-ingress2.yaml
ingress.networking.k8s.io "ingress2" deleted
# k delete -f 08-ingress.yaml
ingress.networking.k8s.io "ingress" deleted
# k delete -f 07-ingress-backend.yaml
deployment.apps "nginx1-deployment" deleted
service "nginx-service-clusterip" deleted
deployment.apps "nginx2-deployment" deleted
service "nginx2-service-clusterip" deleted

...

3. 파드 네트워크

참고) 문서 상 노드 이름 및 역할

...

코드 블럭
root@sung-ubuntu01:~/tmp# kubectl get pod -o wide
NAME          READY   STATUS    RESTARTS   AGE     IP            NODE            NOMINATED NODE   READINESS GATES
ubuntu-test   1/1     Running   0          6m20s   10.233.99.1   sung-ubuntu04   <none>           <none>


###POD 접속
root@sung-ubuntu01:~/tmp# kubectl exec -it ubuntu-test -- bash
root@ubuntu-test:/#

# apt update
# apt install -y net-tools iputils-ping

root@ubuntu-test:/# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=39.6 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=38.1 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=38.8 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=54 time=39.3 ms


# apt update
# apt install -y net-tools iputils-ping


**# 컨테이너의 네트워크 인터페이스 확인**
# root@ubuntu-test:/# ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1480
        inet 10.233.99.1  netmask 255.255.255.255  broadcast 0.0.0.0
        ether 06:55:84:5a:ac:6b  txqueuelen 0  (Ethernet)
        RX packets 5718  bytes 24026416 (24.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3690  bytes 250168 (250.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

#노드와 파드 사이를 연결하는 인터페이스입니다.
tunl0: flags=128<NOARP>  mtu 1480
        tunnel   txqueuelen 1000  (IPIP Tunnel)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

* loopback ip : host 자신을 가리키는 논리적인 인터페이스
**#노드 네트워크 확인**
root@sung-ubuntu04:~# ifconfig -a
...
tunl0: flags=193<UP,RUNNING,NOARP>  mtu 1480
        inet 10.233.99.0  netmask 255.255.255.255
        tunnel   txqueuelen 1000  (IPIP Tunnel)
        RX packets 60  bytes 8528 (8.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 66  bytes 4476 (4.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

*mtu 1480인 이유?
IPIP 터널을 사용하고 있기 때문에, 캡슐화된 패킷의 크기는 원래 패킷보다 더 크기 때문에 MTU 조절이 필요하다
1480인 이유는 캡슐화된 패킷이 Ethernet 패킷에 포함될 때 전체 크기가 1500을 초과하지 않도록 하기 위해서이다.

...