튜토리얼
K8s에서 서비스 네트워크 메시 이스티오를 구성해봅니다.
그리고 키알리를 통해 네트워크 UI를 직접 눈으로 확인해봅니다.
환경
centos7
docker 1.13.1-72 -> 20.10.8
kube 13 -> 22
helm 2.x -> 3.6.3
dashboard 1.10 -> 2.3.1
istio-1.11.0 설치
# k8s master에서 설치함.
> cd istio-1.11.0
> vi ~/.bashrc
export PATH="$PATH:/root/istio-1.11.0/bin"
> istioctl install --set profile=demo -y
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
✔ Egress gateways installed
✔ Installation complete
> kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
istio-egressgateway-765df676b-9qchd 1/1 Running 0 70s
istio-ingressgateway-85fbdd86f7-9bs7m 1/1 Running 0 81s
istiod-5f6b5f485d-s566p 1/1 Running 0 104s
> kubectl label namespace default istio-injection=enabled
> cd istio-1.11.0
> kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
> kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
istioctl analyze
> kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items\[0\].status.hostIP}'
172.16.15.142
> kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports\[?(@.name=="http2")\].nodePort}'
31920
#istio-system에 있는 istio-ingressgateway-XXX POD입니다.
#위 Gateway의 내용은 80포트로 들어오는 모든 HOST에 대해 istio-ingressgateway-xxx POD를 이용하여 proxying하겠다는겁니다.
#80포트라는 번호는 아무렇게나 정한게 아닙니다. 어떻게 정해진걸까요 ?
#istio-ingressgateway-xxx POD가 연결이 되려면 해당하는 Service 리소스를 통해 연결되야 합니다. 어떤 Service인지 찾아 봅시다.
#istio-ingressgateway-xxx POD와 동일한 label을 갖고 있는 Service를 찾습니다.
> kubectl get pod -l istio=ingressgateway --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
istio-system istio-ingressgateway-5dc645f586-8flnt 1/1 Running 0 37m
> kubectl get svc -l istio=ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.99.251.142 <pending> 15021:30758/TCP,80:31920/TCP,443:31703/TCP,31400:30190/TCP,15443:32284/TCP 47m</pending>
#master 에서 접근이 가능한 80 접근하고 ->
모든 호스트에서 접근이 가능한 31920 접근하고 (Gateway 설정)->Service: istio-ingressgateway(설치된 NODE의 IP, 80포트로 수신)
-\> Pod: instio-ingressgateway-XXX( 80포트로 연결) ->
(VirtualService설정)-> Service: productpage( 일반 url는 80으로 연결, 특정 uri패턴으로 요청 9080 포트로 연결) ->
Container in productpage-XXX: istio envoy proxy -> Container in productpage-XXX: productpage
# 외부에서 들어올 수 있도록
> kubectl edit svc istio-ingressgateway -n istio-system
spec:
allocateLoadBalancerNodePorts: true
clusterIP: 10.99.251.142
clusterIPs:
- 10.99.251.142
externalTrafficPolicy: Cluster
externalIPs:
- 172.16.15.140
...
- name: http
port: 18080
protocol: TCP
targetPort: 18080
> kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.99.251.142 172.16.15.140 15021:30758/TCP,80:31920/TCP,443:31703/TCP,31400:30190/TCP,15443:32284/TCP 60m
#모든 HOST가 아닌 hosts를 '*'에서 'bookinfo.$INGRESS_HOST.selee.io'로 바꿔 봅시다.
> kubectl edit Gateway bookinfo-gateway -n default
- hosts:
- 'bookinfo.172.16.15.140.selee.io'
port:
name: http
number: 80
protocol: HTTP
- hosts:
- 'users.172.16.15.140.selee.io'
port:
name: http-users
number: 18080
protocol: HTTP
> kubectl edit VirtualService bookinfo -n default
spec:
gateways:
- bookinfo-gateway
hosts:
- 'bookinfo.172.16.15.140.selee.io'
> cd /root/istio-1.11.0/samples/bookinfo/networking
> vi users-gateway.yaml
kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
name: users
spec:
hosts:
- 'users.172.16.15.140.selee.io'
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /users
route:
- destination:
host: users-svc
port:
number: 8888
# 등록 후 변경 할려면 users 이름
> kubectl edit VirtualService users -n default
> vi users-test-svc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: users-pod
spec:
replicas: 1
selector:
matchLabels:
app: users
template:
metadata:
name: users-pod
labels:
app: users
spec:
containers:
- name: users-container
image: ondalk8s/users-img
imagePullPolicy: Always
ports:
- containerPort: 10001
apiVersion: v1
kind: Service
metadata:
name: users-svc
spec:
selector:
app: users
type: ClusterIP
ports:
- name: users-port
port: 8888
protocol: TCP
targetPort: 8080
> kubectl create -f users-test-svc.yaml
deployment.apps/users-pod created
service/users-svc created
> kubectl create -f users-gateway.yaml
virtualservice.networking.istio.io/users created
# 로컬 클라이언트 측에서 dns 체크
> dig bookinfo.172.16.15.140.selee.io
; <<>\> DiG 9.11.3-1ubuntu1.2-Ubuntu <<>> bookinfo.172.16.15.140.selee.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4114
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;bookinfo.172.16.15.140.selee.io. IN A
;; ANSWER SECTION:
bookinfo.172.16.15.140.selee.io. 0 IN A 172.16.15.140
;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Aug 20 18:11:04 KST 2021
;; MSG SIZE rcvd: 76
> ping bookinfo.172.16.15.140.selee.io
PING bookinfo.172.16.15.140.selee.io (172.16.15.140) 56(84) bytes of data.
64 bytes from bookinfo.172.16.15.140.selee.io (172.16.15.140): icmp_seq=1 ttl=62 time=0.393 ms
64 bytes from bookinfo.172.16.15.140.selee.io (172.16.15.140): icmp_seq=2 ttl=62 time=0.457 ms
productpage 기본 ID / PW는 admin / admin입니다.
- 키알리를 통해 네트워크 토폴로지
외부에서 들어올 수 있도록
kubectl edit svc kiali -n istio-system
spec:
clusterIP: 10.99.31.12
clusterIPs:
> kubectl apply -f samples/addons > kubectl rollout status deployment/kiali -n istio-system
10.99.31.12
externalIPs:
172.16.15.140
아래 예제에서는 http://`172.16.15.140`:20001번으로 접근하면 됩니다.
여러번 누르면 종합적인 그림이 나옴
기본적으로는 v1~v3으로 라운드 로빈으로 돌고있습니다.

어플리케이션을 v1만 적용
```bash
> cd /root/istio-1.11.0/samples/bookinfo/networking
> kubectl apply -f ./destination-rule-all.yaml
> kubectl apply -f ./virtual-service-all-v1.yaml
review v2-v3를 호출하도록 바꿉니다.
> kubectl apply -f ./virtual-service-reviews-v2-v3.yaml
productpage를 접근하여 대여섯번 refresh합니다. v2가 호출되면 검은색 별점이 나타나고, v3가 호출되면 빨간색 별점이 표시됩니다.
그리고 kiali 페이지에서 맨 우측 상단의 refresh아이콘을 누릅니다.
지난 1분의 라우팅을 보여주기 때문에 약간 시간 차이가 발생합니다.
이번에는 review v3를 호출하도록 바꿉니다.
> kubectl apply -f ./virtual-service-reviews-v3.yaml
virtualservice.networking.istio.io/reviews configured
- 삭제방법
istio manifest generate --set profile=demo | kubectl delete -f - 주의 : 기존 istio 관련 edit를 한 정보는 소실됨.
'IT > kubernetes' 카테고리의 다른 글
쿠버네티스 버전 업그레이드 (0) | 2021.09.23 |
---|---|
쿠버네티스 설치 (0) | 2021.09.23 |
프라이빗 도커 레파지토리 Helm에서 Harbor로 설치 (0) | 2021.09.23 |