今天从istioctl到bookinfo再到kiali,重新撸了一次。单体应用,这一刻感觉比前年弄的那一次,真的方便了不少。
一, 下载解压
得到istio-1.7.2目录,先将bin/istioctl拷贝到/usr/local/bin目录。
其它时间,在istio-1.7.2目录下玩就可以了。
二,准备docker镜像
还好,都是可以想办法下载的,不像gcr的仓库,国内下不了。
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
istio/proxyv2 1.7.2 d8fb7dcfd395 6 weeks ago 364MB
istio/pilot 1.7.2 d45159d9caa3 6 weeks ago 278MB
quay.io/kiali/kiali v1.22 86cfc43dddbf 2 months ago 168MB
grafana/grafana 7.0.5 89ec51554c46 4 months ago 159MB
istio/examples-bookinfo-reviews-v3 1.16.2 83e6a8464b84 4 months ago 694MB
istio/examples-bookinfo-reviews-v2 1.16.2 39cff5d782e1 4 months ago 694MB
istio/examples-bookinfo-reviews-v1 1.16.2 181be23dc1af 4 months ago 694MB
istio/examples-bookinfo-ratings-v2 1.16.2 4c23d9a4a44d 4 months ago 161MB
istio/examples-bookinfo-ratings-v1 1.16.2 99ce598b98cf 4 months ago 161MB
istio/examples-bookinfo-details-v2 1.16.2 6be995c3be33 4 months ago 149MB
istio/examples-bookinfo-details-v1 1.16.2 edf6b9bea3db 4 months ago 149MB
istio/examples-bookinfo-productpage-v1 1.16.2 7f1e097aad6d 4 months ago 207MB
jaegertracing/all-in-one 1.18 0e2e4c273c1d 4 months ago 48.3MB
prom/prometheus v2.19.0 39d1866a438a 4 months ago 142MB
openzipkin/zipkin-slim 2.20.0 ec81b0245c0d 8 months ago 122MB
jimmidyson/configmap-reload v0.3.0 7ec24a279487 14 months ago 9.7MB
三,生成一个安装的yaml文件
如果在家里可以连外网,可以直接使用如下命令
istioctl manifest generate --set profile=demo > istio-demo.yaml
但,如果是企业纯内网,那最好将上面的镜像,都改一下tag,放到公司内的harbor仓库中,然后,在生成yaml时,定义一下harbor的地址。
istioctl manifest generate --set .values.global.hub="xxxcom.cn/3rd_part/docker.io/istio" --set profile=demo > istio-demo.yaml
我试过,如果真的一点网都连不上,好像就算本地有那个镜像,也没有毛用,docker还是要远方看一下。
为了方面测试,没有lb环境下,将ingress的service修改为nodeport吧。
apiVersion: v1
kind: Service
metadata:
annotations: null
labels:
app: istio-ingressgateway
istio: ingressgateway
release: istio
name: istio-ingressgateway
namespace: istio-system
spec:
ports:
- name: status-port
port: 15021
targetPort: 15021
- name: http2
port: 80
targetPort: 8080
- name: https
port: 443
targetPort: 8443
- name: tcp
port: 31400
targetPort: 31400
- name: tls
port: 15443
targetPort: 15443
selector:
app: istio-ingressgateway
istio: ingressgateway
type: NodePort
四,部署集群
出于礼貌,可以先建好namespace
kubectl create ns istio-system
我又遇到过不礼貌的,提前没有ns,就是不掉我~
将yaml文件应用到k8s集群
kubectl apply -f istio-demo.yaml
然后,如果一定安好,那就静候时光吧。
kubectl -n istio-system get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-egressgateway ClusterIP 10.43.10.106 <none> 80/TCP,443/TCP,15443/TCP 9m8s
istiod ClusterIP 10.43.8.76 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP,853/TCP 9m8s
istio-ingressgateway NodePort 10.43.29.72 <none> 15021:30717/TCP,80:31101/TCP,443:31853/TCP,31400:30946/TCP,15443:31031/TCP 9m8s
kubectl -n istio-system get pod
NAME READY STATUS RESTARTS AGE
istiod-67b9c76c59-24rrl 1/1 Running 0 10m
istio-ingressgateway-6ffdb76d94-wzjnw 1/1 Running 0 10m
istio-egressgateway-779946795c-vl79w 1/1 Running 0 10m
五,应用bookinfo示例
先把default弄起自动注入sidecar
kubectl label namespace default istio-injection=enabled
来,一把梭哈,输了下海干活,赢了会所嫩模!!!
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
朋友,又期待岁月静好吧。
kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-deployment-559fdddb7b-qn66z 2/2 Running 0 2d16h
details-v1-5dd7f66d97-hmb5s 2/2 Running 0 3m10s
reviews-v3-59b4576599-sbh4n 2/2 Running 0 3m10s
productpage-v1-6dd78fb87f-c94jj 2/2 Running 0 3m10s
reviews-v2-7b7d895d85-jgd9c 2/2 Running 0 3m10s
ratings-v1-fc4ccd4df-99p7z 2/2 Running 0 3m9s
reviews-v1-56f9d844f5-6jkfb 2/2 Running 0 3m9s
六,测试简单的规则访问
应用一下网关
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
路由任意发挥
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
先来命令行模拟,加点鸡血值
kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
确认一下访问端口
[root@localhost software]# kubectl -n istio-system get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-egressgateway ClusterIP 10.43.28.91 <none> 80/TCP,443/TCP,15443/TCP 42m
istio-ingressgateway NodePort 10.43.173.235 <none> 15021:30659/TCP,80:31998/TCP,443:31133/TCP,31400:31511/TCP,15443:32212/TCP 42m
istiod ClusterIP 10.43.113.220 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP,853/TCP 42m
嗯:31998,访问一下http://192.168.1.214:31998/productpage,多刷几次,reviews的几个版本都会出来。
其它流量规则测试不着急,先搞搞其它UI,才齐活~
七,
又是一把梭哈。
kubectl apply -f samples/addons/
这里面,啥都有,kiali, prometheus,jaeger,grafana都有。
学前端一样,将这几个的service都弄成nodeport,看到的界面多哈哈。
如果都是nodeport,那么现在输出如下:
[root@localhost istio-1.7.2]# kubectl get pod -n istio-system
NAME READY STATUS RESTARTS AGE
istiod-95bffc969-67qms 1/1 Running 0 15m
istio-egressgateway-7b49cdb77f-2hbbr 1/1 Running 0 15m
istio-ingressgateway-577b99649b-6nswb 1/1 Running 0 15m
prometheus-9d5676d95-nsg2r 2/2 Running 0 8m56s
grafana-75b5cddb4d-tfm7m 1/1 Running 0 8m57s
jaeger-5795c4cf99-ppqtt 1/1 Running 0 8m56s
kiali-6c49c7d566-gk4dn 1/1 Running 0 8m56s
[root@localhost istio-1.7.2]# kubectl get svc -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-egressgateway ClusterIP 10.43.28.91 <none> 80/TCP,443/TCP,15443/TCP 15m
istio-ingressgateway NodePort 10.43.173.235 <none> 15021:30659/TCP,80:31998/TCP,443:31133/TCP,31400:31511/TCP,15443:32212/TCP 15m
istiod ClusterIP 10.43.113.220 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP,853/TCP 15m
kiali NodePort 10.43.11.85 <none> 20001:32475/TCP,9090:30778/TCP 9m2s
grafana NodePort 10.43.148.20 <none> 3000:30137/TCP 9m3s
tracing NodePort 10.43.170.152 <none> 80:31277/TCP 9m2s
zipkin NodePort 10.43.24.116 <none> 9411:32689/TCP 9m2s
prometheus NodePort 10.43.166.219 <none> 9090:31285/TCP
八,更新kiali的configmap设置
kubectl edit configmap -n istio-system kiali
按下图的套路来。
我觉得应该可以直接在Yaml里搞,但这里这样快
删除这个kiali的pod,自动重新建POD,让configmap更新生效。
kubectl delete pod -n istio-system $(kubectl get pod -n istio-system | grep -i kiali | awk '{print $1}')
九,UI测试
多访问bookinfo(http://192.168.1.214:31998/productpage)几次,然后,去看看各个UI的功能吧。
http://192.168.1.214:32475/kiali/console/overview?duration=60&refresh=15000
http://192.168.1.214:31277/jaeger/search
http://192.168.1.214:30137/d/UbsSZTDik/istio-workload-dashboard?orgId=1&var-workload=ratings-v1&var-namespace=default&refresh=10s
十,铲除istio
删除应用,再加下面两条命令,应该妥妥的。
samples/bookinfo/platform/kube/cleanup.sh
kubectl delete ns istio-system