Istio And Kubernetes on premise

Watchara Ph
devopsthailand
Published in
3 min readOct 30, 2018

จากตอนแรกเราได้จำลอง Kubernetes on Premise ( https://goo.gl/QuSCrb ) วันนี้เราเลยจะมาลอง Istio ของ Prem กันครับว่ารูปร่างหน้าตามันจะเป็นยังงัยบ้างแต่ก่อนอื่นเรามารู้จัก Istio คืออะไร กันก่อนนะครับ

Istio มีหน้าที่จัดการ connect, manage และ secure microservices ซึ่งรองรับ Kubernetes โดยหลักๆ แล้ว Istio ช่วยให้เราจัดการ service mesh ได้ง่ายขึ้น เพราะ Istio provides cross-cutting concerns เช่น service discovery, monitoring, metrics, load balancing, rate limiting และอื่นๆ อีกมากมายซึ่ง Istio มี architecture ตามภาพด้านล่าง ส่วนรายละเอียดแต่ล่ะส่วนทำอะไรบ้างรอติดตามในบทต่อๆ ไป แต่ตอนนี้เรามา Install Istio กับ เตรียม example กันครับ

Example นี้ก็ได้มาจาก Web Istio เองนะครับ ซึ่งจะได้ application ตามภาพครับ และเราจะใช้ example นี้ในบทต่อไปด้วยครับ

1.Install istio with Kubernetes on prem

Check status Kubernetes cluster

$ kubectl cluster-info

Install Istio version 1.0.3 ( Latest on November )

$ curl -L https://git.io/getLatestIstio | sh -

$ export PATH=”$PATH:/root/istio-1.0.3/bin”

$ cd $HOME/istio-1.0.3

$ kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml

$ kubectl apply -f install/kubernetes/istio-demo.yaml

จะเห็นว่าหลังจาก Install Istio แล้วจะติดตั้งทั้ง traffic manament, security control, proxy, sidecar, pilot, etc. รวมไปถึง Tool Monitors ต่างๆ รวมถึง Espose Services อยู่ใน namespace istio-system

Verify pods and services

$ kubectl get pod -n istio-system

$ kubectl get svc -n istio-system

ทำการ enable istio injection ใน namespace default

$ kubectl get namespace -L istio-injection

$ kubectl label namespace default istio-injection=enabled

2. Deploy Application and Service ซึ่งแบ่งออกเป็น

productpage-v1 deployment=istio/examples-bookinfo-productpage-v1:1.8.0 serviceport=9080 version=v1

reviews-v1 deployment=istio/examples-bookinfo-reviews-v1:1.8.0 service=reviews:9080 version=v1

reviews-v2 deployment=istio/examples-bookinfo-reviews-v2:1.8.0 service=reviews:9080 version=v2

reviews-v3 deployment=istio/examples-bookinfo-reviews-v3:1.8.0 service=reviews:9080 version=v3

ratings-v1 deployment=istio/examples-bookinfo-ratings-v1:1.8.0 service=ratings:9080 version=v1

details-v1 deployment=istio/examples-bookinfo-details-v1:1.8.0 service=details:9080 version=v1

$ cat samples/bookinfo/platform/kube/bookinfo.yaml

$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml

หลังจาก apply bookinfo.yaml แล้วจะพบว่าจะถูก deploy ที่ namespace default ซึ่งก่อนหน้านี้เราก็ apply istio injection ไปยัง namespace default รอไว้แล้ว

ลองดูข้อมูลของ pod จะเห็นว่ามี proxy อยู่ใน pod ด้วย

$ kubectl describe pod ratings-v1–575c5c4948–46cp8

3.สร้าง Gateway ระหว่าง Services กับ Gateway

$ cat samples/bookinfo/networking/bookinfo-gateway.yaml

$ kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

$ kubectl get gateway

4. Verify Service เนื่องจาก เราเป็น NodePort เพราะเราทำบน On Premise ไม่มี external ip วิธีเช็ค nodeport ในการเรียก ส่วนวิธีอื่นลองดูที่นี่ได้ครับ

$ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath=’{.spec.ports[?(@.name==”http2")].nodePort}’)

$ export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath=’{.spec.ports[?(@.name==”https”)].nodePort}’)

$ export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o ‘jsonpath={.items[0].status.hostIP}’)

$ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT

$ curl -o /dev/null -s -w “%{http_code}\n” http://${GATEWAY_URL}/productpage

--

--