环境说明
-
frontend(proxy):前端应用,会请求后端的demoapp
-
service: proxy
-
-
demoapp:后端应用
-
service: demoappv10
-
- 访问流程
- client pod —> (Egress Listener proxy:80) client sidecar Envoy —> (Ingress Listener ) proxy pod —> (Egress Listener) demoappv10:8080 —> (Ingress Listener) demoappv10 pod
开启Istio sidecar自动注入功能
# kubectl label namespace default istio-injection=enabled
namespace/default labeled
创建demoapp应用
创建demoapp配置清单
生成depoly-demoapp-v10.yaml
# kubectl create deployment demoappv10 --image=ikubernetes/demoapp:v1.0 --replicas=3 --dry-run=client -o yaml > depoly-demoapp-v10.yaml
修改depoly-demoapp-v10.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: demoapp
version: v1.0
name: demoappv10
spec:
replicas: 3
selector:
matchLabels:
app: demoappv10
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: demoapp
version: v1.0
spec:
containers:
- image: ikubernetes/demoapp:v1.0
name: demoapp
env:
- name: PORT
value: "8080"
resources: {}
创建demoapp svc配置清单
生成service-demoapp-v10.yaml
# kubectl create service clusterip demoappv10 --tcp=8080:8080 --dry-run=client -o yaml > service-demoapp-v10.yaml
修改service-demoapp-v10.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: demoapp
name: demoappv10
spec:
ports:
- name: http-8080
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: demoapp
version: v1.0
type: ClusterIP
创建demoapp资源
生成demoapp pod
# kubectl apply -f .
deployment.apps/demoappv10 created
service/demoappv10 created
查看demoapp pod
# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
demoappv10-6ffb8d999c-pzrpm 2/2 Running 0 4m22s 172.20.154.214 192.168.174.106 <none> <none>
demoappv10-6ffb8d999c-smtmt 2/2 Running 0 4m22s 172.20.44.236 192.168.174.107 <none> <none>
demoappv10-6ffb8d999c-z6jmn 2/2 Running 0 4m22s 172.20.89.160 192.168.174.108 <none> <none>
生成demoapp pod变量
# DEMOAPP_POD=$(kubectl get pods -l app=demoapp -o jsonpath={.items[0].metadata.name})
查看demoapp 网格内状态
查看listeners
~# istioctl proxy-config listeners $DEMOAPP_POD --port 8080
ADDRESS PORT MATCH DESTINATION
0.0.0.0 8080 Trans: raw_buffer; App: http/1.1,h2c Route: 8080
0.0.0.0 8080 ALL PassthroughCluster
查看routes
~# istioctl proxy-config routes $DEMOAPP_POD
NAME DOMAINS MATCH VIRTUAL SERVICE
grafana.istio-system.svc.cluster.local:3000 * /*
15010 istiod.istio-system, 10.100.149.76 /*
kube-dns.kube-system.svc.cluster.local:9153 * /*
kubernetes-dashboard.kubernetes-dashboard.svc.cluster.local:443 * /*
jaeger-collector.istio-system.svc.cluster.local:14250 * /*
9411 jaeger-collector.istio-system, 10.100.122.235 /*
9411 zipkin.istio-system, 10.100.29.132 /*
dashboard-metrics-scraper.kubernetes-dashboard.svc.cluster.local:8000 * /*
80 istio-egressgateway.istio-system, 10.100.121.95 /*
80 istio-ingressgateway.istio-system, 10.100.145.112 /*
80 tracing.istio-system, 10.100.92.199 /*
InboundPassthroughClusterIpv4 * /*
8080 demoappv10, demoappv10.default + 1 more... /*
jaeger-collector.istio-system.svc.cluster.local:14268 * /*
inbound|8080|| * /*
9090 kiali.istio-system, 10.100.48.203 /*
9090 prometheus.istio-system, 10.100.42.102 /*
inbound|8080|| * /*
istio-ingressgateway.istio-system.svc.cluster.local:15021 * /*
* /stats/prometheus*
* /healthz/ready*
InboundPassthroughClusterIpv4 * /*
15014 istiod.istio-system, 10.100.149.76 /*
16685 tracing.istio-system, 10.100.92.199 /*
20001 kiali.istio-system, 10.100.48.203 /*
查看endpoint
~# istioctl proxy-config endpoint $DEMOAPP_POD --cluster "outbound|8080||demoappv10.default.svc.cluster.local"
ENDPOINT STATUS OUTLIER CHECK CLUSTER
172.20.154.215:8080 HEALTHY OK outbound|8080||demoappv10.default.svc.cluster.local
172.20.44.237:8080 HEALTHY OK outbound|8080||demoappv10.default.svc.cluster.local
172.20.89.161:8080 HEALTHY OK outbound|8080||demoappv10.default.svc.cluster.local
在网格内访问demoapp
创建client
~# kubectl run client --image=ikubernetes/admin-box -it --rm --restart=Never --command -- /bin/sh
If you don't see a command prompt, try pressing enter.
root@client #
查看client 端口
root@client # netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:15006 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:15006 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:15001 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:15001 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:15021 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:15021 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:15000 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:15004 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:15090 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:15090 0.0.0.0:* LISTEN -
tcp 0 0 :::15020 :::* LISTEN -
访问demo app
root@client # curl demoappv10:8080 #不是通过demoapp svc, 通过主机名称访问,envoy代理 listener 监听8080端口
iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.6, ServerName: demoappv10-78b6586d58-h7kpb, ServerIP: 172.20.89.161!
在kiali查看访问流程
创建proxy
depoly-proxy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: proxy
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
app: proxy
template:
metadata:
labels:
app: proxy
spec:
containers:
- env:
- name: PROXYURL
value: http://demoappv10:8080
image: ikubernetes/proxy:v0.1.1
imagePullPolicy: IfNotPresent
name: proxy
ports:
- containerPort: 8080
name: web
protocol: TCP
resources:
limits:
cpu: 50m
---
apiVersion: v1
kind: Service
metadata:
name: proxy
spec:
ports:
- name: http-80 # 固定格式协议+端口号
port: 80
protocol: TCP
targetPort: 8080
selector:
app: proxy
---
创建proxy资源
# kubectl apply -f depoly-proxy.yaml
deployment.apps/proxy created
service/proxy created
查看 proxy pod
# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
client 2/2 Running 0 34m 172.20.89.162 192.168.174.108 <none> <none>
demoappv10-78b6586d58-bwjmh 2/2 Running 0 57m 172.20.44.237 192.168.174.107 <none> <none>
demoappv10-78b6586d58-h7kpb 2/2 Running 0 57m 172.20.89.161 192.168.174.108 <none> <none>
demoappv10-78b6586d58-z9mht 2/2 Running 0 57m 172.20.154.215 192.168.174.106 <none> <none>
proxy-7b79687bbc-bmz7x 2/2 Running 0 2m42s 172.20.154.216 192.168.174.106 <none> <none>
查看proxy svc
# kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
demoappv10 ClusterIP 10.100.15.159 <none> 8080/TCP 57m app=demoapp,version=v1.0
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 8d <none>
proxy ClusterIP 10.100.39.182 <none> 80/TCP 2m53s app=proxy
在网格内通过proxy访问demoapp
创建client
~# kubectl run client --image=ikubernetes/admin-box -it --rm --restart=Never --command -- /bin/sh
If you don't see a command prompt, try pressing enter.
root@client #
访问demo app
root@client # curl proxy
Proxying value: iKubernetes demoapp v1.0 !! ClientIP: 127.0.0.6, ServerName: demoappv10-78b6586d58-bwjmh, ServerIP: 172.20.44.237!
- Took 318 milliseconds.
在kiali查看访问流程
原文地址:http://www.cnblogs.com/wangguishe/p/16813930.html
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请务用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性