Bookinfo
- ProductPage 페이지에서 요청을 받으면, 도서 리뷰를 보여주는 Reviews 서비스와 도서 상세 정보를 보여주는 Details 서비스에 접속
- ProductPage는 reviews와 Details 결과를 사용자에게 응답한다.
- Reviews 서비스는 v1, v2, v3 세 개의 버전이 있고 v2, v3 버전의 경우 Ratings 서비스에 접소갛여 도서에 대한 5단계 평가를 가져옴
- Reviews 서비스의 차이는, v1은 Rating 이없고, v2는 검은색 별로 Ratings 가 표시되며, v3는 색깔이 있는 별로 Ratings 가 표시
실습 시작
예제 yaml은 istioctl 설치 시 포함되어 있는 bookinfo 예제입니다.
# 모니터링
$ watch -d 'kubectl get pod -owide;echo;kubectl get svc'
# Bookinfo 애플리케이션 배포
$ echo $ISTIOV
$ cat ~/istio-$ISTIOV/samples/bookinfo/platform/kube/bookinfo.yaml
$ kubectl apply -f ~/istio-$ISTIOV/samples/bookinfo/platform/kube/bookinfo.yaml
- 생성 확인
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
details-v1-65cfcf56f9-rl5l7 2/2 Running 0 50s 172.16.2.5 k3s-w1 <none> <none>
productpage-v1-d5789fdfb-gt567 2/2 Running 0 49s 172.16.1.6 k3s-w2 <none> <none>
ratings-v1-7c9bd4b87f-vjbsx 2/2 Running 0 50s 172.16.1.4 k3s-w2 <none> <none>
reviews-v1-6584ddcf65-hznqk 2/2 Running 0 49s 172.16.2.6 k3s-w1 <none> <none>
reviews-v2-6f85cb9b7c-5t6tt 2/2 Running 0 49s 172.16.1.5 k3s-w2 <none> <none>
reviews-v3-6f5b775685-mmtdk 2/2 Running 0 49s 172.16.2.7 k3s-w1 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
details ClusterIP 10.10.200.135 <none> 9080/TCP 50s
kubernetes ClusterIP 10.10.200.1 <none> 443/TCP 5m19s
productpage ClusterIP 10.10.200.209 <none> 9080/TCP 49s
ratings ClusterIP 10.10.200.129 <none> 9080/TCP 50s
reviews ClusterIP 10.10.200.158 <none> 9080/TCP 50s
- pod 내부에서 Product 웹 접속 확인
(⎈|default:N/A) root@k3s-s:~# kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
- Logs 확인 (빨강 : app 로그, 초록 : Istio 로그)
Isto를 통한 인입 기본 설정
- bookinfo-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
# The selector matches the ingress gateway pod labels.
# If you installed Istio using Helm following the standard documentation, this would be "istio=ingress"
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 8080
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "*"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
prefix: /static
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
- 배포 진행
## 리소스 생성 확인
(⎈|default:N/A) root@k3s-s:~# k get gw,vs
NAME AGE
gateway.networking.istio.io/bookinfo-gateway 11s
NAME GATEWAYS HOSTS AGE
virtualservice.networking.istio.io/bookinfo ["bookinfo-gateway"] ["*"] 11s
## istioctl 확인
(⎈|default:N/A) root@k3s-s:~# istioctl proxy-status
NAME CLUSTER CDS LDS EDS RDS ECDS ISTIOD VERSION
details-v1-65cfcf56f9-rl5l7.default Kubernetes SYNCED (15m) SYNCED (15m) SYNCED (15m) SYNCED (15m) IGNORED istiod-7f8b586864-4c46w 1.23.2
istio-ingressgateway-5f9f654d46-kt5cm.istio-system Kubernetes SYNCED (22s) SYNCED (22s) SYNCED (9m24s) SYNCED (22s) IGNORED istiod-7f8b586864-4c46w 1.23.2
productpage-v1-d5789fdfb-gt567.default Kubernetes SYNCED (5m50s) SYNCED (5m50s) SYNCED (5m50s) SYNCED (5m50s) IGNORED istiod-7f8b586864-4c46w 1.23.2
ratings-v1-7c9bd4b87f-vjbsx.default Kubernetes SYNCED (11m) SYNCED (11m) SYNCED (11m) SYNCED (11m) IGNORED istiod-7f8b586864-4c46w 1.23.2
reviews-v1-6584ddcf65-hznqk.default Kubernetes SYNCED (15m) SYNCED (15m) SYNCED (15m) SYNCED (15m) IGNORED istiod-7f8b586864-4c46w 1.23.2
reviews-v2-6f85cb9b7c-5t6tt.default Kubernetes SYNCED (9m1s) SYNCED (9m1s) SYNCED (9m1s) SYNCED (9m1s) IGNORED istiod-7f8b586864-4c46w 1.23.2
reviews-v3-6f5b775685-mmtdk.default Kubernetes SYNCED (14m) SYNCED (14m) SYNCED (14m) SYNCED (14m) IGNORED istiod-7f8b586864-4c46w 1.23.2
- 접속 확인
## NodePort 변수 지정
(⎈|default:N/A) root@k3s-s:~# export IGWHTTP=$(kubectl get service -n istio-system istio-ingressgateway -o jsonpath='{.spec.ports[1].nodePort}')
(⎈|default:N/A) root@k3s-s:~# echo $IGWHTTP
32469
## Control Plane, Worker Node1,2로 바로 확인
(⎈|default:N/A) root@k3s-s:~# curl -Is http://localhost:$IGWHTTP/productpage
HTTP/1.1 200 OK
server: istio-envoy
date: Sat, 19 Oct 2024 18:32:41 GMT
content-type: text/html; charset=utf-8
content-length: 15072
vary: Cookie
x-envoy-upstream-service-time: 938
(⎈|default:N/A) root@k3s-s:~# curl -Is http://192.168.10.101:$IGWHTTP/productpage
HTTP/1.1 200 OK
server: istio-envoy
date: Sat, 19 Oct 2024 18:32:49 GMT
content-type: text/html; charset=utf-8
content-length: 15068
vary: Cookie
x-envoy-upstream-service-time: 87
(⎈|default:N/A) root@k3s-s:~# curl -Is http://192.168.10.102:$IGWHTTP/productpage
HTTP/1.1 200 OK
server: istio-envoy
date: Sat, 19 Oct 2024 18:32:59 GMT
content-type: text/html; charset=utf-8
content-length: 15068
vary: Cookie
x-envoy-upstream-service-time: 61
## 도메인으로도 확인
(⎈|default:N/A) root@k3s-s:~# curl -Is http://$MYDOMAIN:$IGWHTTP/productpage
HTTP/1.1 200 OK
server: istio-envoy
date: Sat, 19 Oct 2024 18:34:06 GMT
content-type: text/html; charset=utf-8
content-length: 15068
vary: Cookie
x-envoy-upstream-service-time: 49
## testPC에서도 확인
root@testpc:~# curl -Is $MYDOMAIN:$IGWHTTP/productpage
HTTP/1.1 200 OK
server: istio-envoy
date: Sat, 19 Oct 2024 18:35:00 GMT
content-type: text/html; charset=utf-8
content-length: 9429
vary: Cookie
x-envoy-upstream-service-time: 21
## Local PC에서 확인
7w ➤ curl -sI $MYDOMAIN:$IGWHTTP/productpage
HTTP/1.1 200 OK
server: istio-envoy
date: Sat, 19 Oct 2024 18:36:41 GMT
content-type: text/html; charset=utf-8
content-length: 15072
vary: Cookie
x-envoy-upstream-service-time: 43
- Local PC의 브라우저를 통해서도 접속해보고 Book Reviews와 Rating의 변경을 확인합니다.
모니터링
Addon 설치 : Kiali (키알리) 대시보드 along with Prometheus, Grafana, and Jaeger
(⎈|default:N/A) root@k3s-s:~# tree ~/istio-$ISTIOV/samples/addons/
/root/istio-1.23.2/samples/addons/
├── README.md
├── extras
│ ├── prometheus-operator.yaml
│ ├── skywalking.yaml
│ └── zipkin.yaml
├── grafana.yaml
├── jaeger.yaml
├── kiali.yaml
├── loki.yaml
└── prometheus.yaml
- sample code 확인 후 디렉터리 내의 yaml 파일 배포
(⎈|default:N/A) root@k3s-s:~# k apply -f ~/istio-$ISTIOV/samples/addons
serviceaccount/grafana created
configmap/grafana created
service/grafana created
deployment.apps/grafana created
configmap/istio-grafana-dashboards created
configmap/istio-services-grafana-dashboards created
deployment.apps/jaeger created
service/tracing created
service/zipkin created
service/jaeger-collector created
serviceaccount/kiali created
configmap/kiali created
clusterrole.rbac.authorization.k8s.io/kiali created
clusterrolebinding.rbac.authorization.k8s.io/kiali created
role.rbac.authorization.k8s.io/kiali-controlplane created
rolebinding.rbac.authorization.k8s.io/kiali-controlplane created
service/kiali created
deployment.apps/kiali created
serviceaccount/loki created
configmap/loki created
configmap/loki-runtime created
service/loki-memberlist created
service/loki-headless created
service/loki created
statefulset.apps/loki created
serviceaccount/prometheus created
configmap/prometheus created
clusterrole.rbac.authorization.k8s.io/prometheus created
clusterrolebinding.rbac.authorization.k8s.io/prometheus created
service/prometheus created
deployment.apps/prometheus created
(⎈|default:N/A) root@k3s-s:~# kubectl rollout status deployment/kiali -n istio-system
Waiting for deployment "kiali" rollout to finish: 0 of 1 updated replicas are available...
deployment "kiali" successfully rolled out
- 생성된 리소스 확인
(⎈|default:N/A) root@k3s-s:~# k get all,sa,cm -n istio-system
NAME READY STATUS RESTARTS AGE
pod/grafana-7f76bc9cdb-gjtqb 1/1 Running 0 54s
pod/istio-ingressgateway-5f9f654d46-kt5cm 1/1 Running 0 3h21m
pod/istiod-7f8b586864-4c46w 1/1 Running 0 3h21m
pod/jaeger-66f9675c7b-vlpxk 1/1 Running 0 54s
pod/kiali-65c46f9d98-4p4sm 1/1 Running 0 54s
pod/loki-0 0/1 Running 0 54s
pod/prometheus-7979bfd58c-9994g 2/2 Running 0 54s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/grafana ClusterIP 10.10.200.175 <none> 3000/TCP 55s
service/istio-ingressgateway NodePort 10.10.200.143 <none> 15021:31481/TCP,80:32469/TCP,443:32758/TCP,31400:32504/TCP,15443:31727/TCP 3h21m
service/istiod ClusterIP 10.10.200.43 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 3h21m
service/jaeger-collector ClusterIP 10.10.200.110 <none> 14268/TCP,14250/TCP,9411/TCP,4317/TCP,4318/TCP 54s
service/kiali ClusterIP 10.10.200.40 <none> 20001/TCP,9090/TCP 54s
service/loki ClusterIP 10.10.200.35 <none> 3100/TCP,9095/TCP 54s
service/loki-headless ClusterIP None <none> 3100/TCP 54s
service/loki-memberlist ClusterIP None <none> 7946/TCP 54s
service/prometheus ClusterIP 10.10.200.127 <none> 9090/TCP 54s
service/tracing ClusterIP 10.10.200.205 <none> 80/TCP,16685/TCP 54s
service/zipkin ClusterIP 10.10.200.167 <none> 9411/TCP 54s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/grafana 1/1 1 1 55s
deployment.apps/istio-ingressgateway 1/1 1 1 3h21m
deployment.apps/istiod 1/1 1 1 3h21m
deployment.apps/jaeger 1/1 1 1 54s
deployment.apps/kiali 1/1 1 1 54s
deployment.apps/prometheus 1/1 1 1 54s
NAME DESIRED CURRENT READY AGE
replicaset.apps/grafana-7f76bc9cdb 1 1 1 55s
replicaset.apps/istio-ingressgateway-5f9f654d46 1 1 1 3h21m
replicaset.apps/istiod-7f8b586864 1 1 1 3h21m
replicaset.apps/jaeger-66f9675c7b 1 1 1 54s
replicaset.apps/kiali-65c46f9d98 1 1 1 54s
replicaset.apps/prometheus-7979bfd58c 1 1 1 54s
NAME READY AGE
statefulset.apps/loki 0/1 54s
NAME SECRETS AGE
serviceaccount/default 0 3h21m
serviceaccount/grafana 0 55s
serviceaccount/istio-ingressgateway-service-account 0 3h21m
serviceaccount/istio-reader-service-account 0 3h21m
serviceaccount/istiod 0 3h21m
serviceaccount/kiali 0 54s
serviceaccount/loki 0 54s
serviceaccount/prometheus 0 54s
NAME DATA AGE
configmap/grafana 3 55s
configmap/istio 2 3h21m
configmap/istio-ca-root-cert 1 3h21m
configmap/istio-gateway-status-leader 0 3h21m
configmap/istio-grafana-dashboards 3 55s
configmap/istio-leader 0 3h21m
configmap/istio-namespace-controller-election 0 3h21m
configmap/istio-services-grafana-dashboards 4 54s
configmap/istio-sidecar-injector 2 3h21m
configmap/kiali 1 54s
configmap/kube-root-ca.crt 1 3h21m
configmap/loki 1 54s
configmap/loki-runtime 1 54s
configmap/prometheus 6 54s
- 접근을 위해 kiali svervice type 변경
(⎈|default:N/A) root@k3s-s:~# k patch svc -n istio-system kiali -p '{"spec":{"type":"NodePort"}}'
service/kiali patched
- kiali 웹 주소 확인 및 접속
(⎈|default:N/A) root@k3s-s:~# KIALINodePort=$(kubectl get svc -n istio-system kiali -o jsonpath={.spec.ports[0].nodePort})
(⎈|default:N/A) root@k3s-s:~# echo -e "KIALI UI URL = http://$(curl -s ipinfo.io/ip):$KIALINodePort"
KIALI UI URL = http://43.201.45.35:31512
생성한 kiali의 Traffic Graph에서도 트래픽 흐름을 확인해 볼 수 있습니다.
- grafana 서비스 변경
(⎈|default:N/A) root@k3s-s:~# k patch svc -n istio-system grafana -p '{"spec":{"type":"NodePort"}}'
service/grafana patched
- grafana 웹 주소 확인 및 접속
(⎈|default:N/A) root@k3s-s:~# GRAFANANodePort=$(kubectl get svc -n istio-system grafana -o jsonpath={.spec.ports[0].nodePort})
echo -e "Grafana URL = http://$(curl -s ipinfo.io/ip):$GRAFANANodePort"
Grafana URL = http://43.201.45.35:31529
기본적으로 대시보드가 생성되어 있으며 대시보드를 통해 모니터링도 확인할 수 있습니다.
- prometheus 서비스 타입 변경
(⎈|default:N/A) root@k3s-s:~# k patch svc -n istio-system prometheus -p '{"spec":{"type":"NodePort"}}'
service/prometheus patched
- prometheus 웹 주소 확인 및 접속
(⎈|default:N/A) root@k3s-s:~# PROMENodePort=$(kubectl get svc -n istio-system prometheus -o jsonpath={.spec.ports[0].nodePort})
echo -e "Prometheus URL = http://$(curl -s ipinfo.io/ip):$PROMENodePort"
Prometheus URL = http://43.201.45.35:31391
prometheus에서도 기본적으로 생성되어 있는 정보를 통해 데이터를 확인해 볼수 있습니다.
'Cloud > Kubernetes' 카테고리의 다른 글
[KANS] Cilium & Hubble (0) | 2024.10.26 |
---|---|
[KANS] Istio - Traffic Management (0) | 2024.10.20 |
[KANS] istio install + expose (0) | 2024.10.20 |
[KANS] Gateway API (3) | 2024.10.13 |
[KANS] Ingress (0) | 2024.10.13 |