Istio-0.8.0在Minikube環(huán)境中快速啟動(dòng)Bookinfo示例
之前發(fā)表了從零開(kāi)始應(yīng)用Istio--入門示例,使用的istio版本比較低,在0.8.0版本下發(fā)現(xiàn)很多命令不一樣了,所以總結(jié)一下,重新跑一下Bookinfo.
一. 安裝Minikube環(huán)境
使用Minikube的本地實(shí)驗(yàn)環(huán)境, 系統(tǒng)為centos7.0, 國(guó)內(nèi)環(huán)境安裝可以參考https://yq.aliyun.com/articles/221687
安裝VirtualBox
安裝kubectl
可參考官網(wǎng)提供的安裝說(shuō)明,Install kubectl binary via curl
通過(guò)命令安裝:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
如果安裝失敗,或者無(wú)法訪問(wèn)可以直接下載
https://storage.googleapis.com/kubernetes-release/release/v1.11.1/bin/linux/amd64/kubectl
然后執(zhí)行
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
安裝Minikube
參考Minikube - Kubernetes本地實(shí)驗(yàn)環(huán)境 使用阿里提供的Minikube版本, 我這里使用Kubernetes 1.10 release的版本
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.28.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
啟動(dòng)
minikube start \
--registry-mirror=https://registry.docker-cn.com \
--extra-config=controller-manager.cluster-signing-cert-file="/var/lib/localkube/certs/ca.crt" \
--extra-config=controller-manager.cluster-signing-key-file="/var/lib/localkube/certs/ca.key" \
--extra-config=apiserver.admission-control="NamespaceLifecycle,LimitRanger,ServiceAccount,PersistentVolumeLabel,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" \
--kubernetes-version=v1.10.0
二. 安裝istio
獲取Istio release , 我本地使用的為0.8.0版本
$ curl -L https://git.io/getLatestIstio | sh -
或者在GitHub下載所需版本
進(jìn)入istio目錄
cd istio-0.8.0
添加istioctl 到PATH
export PATH=$PWD/bin:$PATH
安裝, 這里為了方便安裝了不帶TLS的版本
$ kubectl apply -f install/kubernetes/istio-demo.yaml
查看是否安裝正常,看istio-pilot
, istio-ingressgateway
, istio-policy
, istio-telemetry
, prometheus
, 以及可選的istio-sidecar-injector
服務(wù)是否部署
kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-citadel ClusterIP 10.110.18.88 <none> 8060/TCP,9093/TCP 16h
istio-egressgateway ClusterIP 10.105.97.56 <none> 80/TCP,443/TCP 16h
istio-ingressgateway LoadBalancer 10.109.76.80 <pending> 80:31380/TCP,443:31390/TCP,31400:31400/TCP 16h
istio-pilot ClusterIP 10.108.201.57 <none> 15003/TCP,15005/TCP,15007/TCP,15010/TCP,15011/TCP,8080/TCP,9093/TCP 16h
istio-policy ClusterIP 10.100.249.185 <none> 9091/TCP,15004/TCP,9093/TCP 16h
istio-sidecar-injector ClusterIP 10.110.68.171 <none> 443/TCP 16h
istio-statsd-prom-bridge ClusterIP 10.100.113.133 <none> 9102/TCP,9125/UDP 16h
istio-telemetry ClusterIP 10.109.5.24 <none> 9091/TCP,15004/TCP,9093/TCP,42422/TCP 16h
prometheus ClusterIP 10.99.110.28 <none> 9090/TCP
查看pods
kubectl get pods -n istio-system
NAME READY STATUS RESTARTS AGE
istio-citadel-dcb7955f6-vdcjk 1/1 Running 0 11h
istio-egressgateway-56b7758b44-l5fm5 1/1 Running 0 11h
istio-ingressgateway-56cfddbd5b-xbdcx 1/1 Running 0 11h
istio-pilot-cbd6bfd97-wgw9b 2/2 Running 0 11h
istio-policy-699fbb45cf-bc44r 2/2 Running 0 11h
istio-statsd-prom-bridge-949999c4c-nws5j 1/1 Running 0 11h
istio-telemetry-55b675d8c-kfvvj 2/2 Running 0 11h
prometheus-86cb6dd77c-5j48h 1/1 Running 0 11h
這樣istio就安裝完成了
注:
如果沒(méi)有安裝Istio-sidecar-injector, 那么在部署應(yīng)用時(shí)需要手動(dòng)的注入Envoy,
命令如下:
kubectl create -f <(istioctl kube-inject -f <your-app-spec>.yaml)
(*)卸載
如果實(shí)驗(yàn)完成后不在需要Istio
環(huán)境可以使用如下命令卸載Istio
$ kubectl delete -f install/kubernetes/istio-demo.yaml
三. 部署B(yǎng)ookinfo應(yīng)用
使用如下命令安裝應(yīng)用容器,這會(huì)花費(fèi)一點(diǎn)時(shí)間
kubectl apply -f samples/bookinfo/kube/bookinfo.yaml
為應(yīng)用定義ingress網(wǎng)關(guān)
istioctl create -f samples/bookinfo/routing/bookinfo-gateway.yaml
查看所有的服務(wù)都處在運(yùn)行(Running
)狀態(tài)
kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
details 10.0.0.31 <none> 9080/TCP 6m
kubernetes 10.0.0.1 <none> 443/TCP 7d
productpage 10.0.0.120 <none> 9080/TCP 6m
ratings 10.0.0.15 <none> 9080/TCP 6m
reviews 10.0.0.170 <none> 9080/TCP 6m
查看pods
kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-1520924117-48z17 2/2 Running 0 6m
productpage-v1-560495357-jk1lz 2/2 Running 0 6m
ratings-v1-734492171-rnr5l 2/2 Running 0 6m
reviews-v1-874083890-f0qf0 2/2 Running 0 6m
reviews-v2-1343845940-b34q5 2/2 Running 0 6m
reviews-v3-1813607990-8ch52 2/2 Running 0 6m
使用ngress的IP 和 port訪問(wèn)應(yīng)用
這里主要介紹Minikube方式,如果是其他環(huán)境請(qǐng)參考Determining the ingress IP and ports
執(zhí)行
kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.109.76.80 <pending> 80:31380/TCP,443:31390/TCP,31400:31400/TCP 16h
此處EXTERNAL-IP
的值為<pending>
在這種情況下可以通過(guò)服務(wù)的node port
訪問(wèn)gateway
獲取訪問(wèn)端口
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http")].nodePort}')
Minikube環(huán)境下獲取訪問(wèn)IP
export INGRESS_HOST=$(minikube ip)
Set GATEWAY_URL:
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
訪問(wèn)
curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage
結(jié)果 200
如果Minikube 的IP本地可以訪問(wèn),可以用瀏覽器打開(kāi)http://$GATEWAY_URL/productpage
訪問(wèn)Bookinfo的web頁(yè)面.
Cleanup Bookinfo
刪除路由,終止應(yīng)用pods
samples/bookinfo/kube/cleanup.sh
確認(rèn)是否關(guān)閉
istioctl get gateway #-- there should be no more gateway
istioctl get virtualservices #-- there should be no more virtual services
kubectl get pods #-- the Bookinfo pods should be deleted