环境说明
-
frontend(proxy):前端应用,会请求后端的demoapp
- service: proxy
-
demoapp:后端应用
- 同时部署两个版本
部署demoappv1.0
deploy-demoapp-v10.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: demoappv10
version: v1.0
name: demoappv10
spec:
replicas: 2
selector:
matchLabels:
app: demoapp
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: {}
service-demoapp-v10.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: demoappv10
name: demoappv10
spec:
ports:
- name: http-8080
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: demoapp
version: v1.0
type: ClusterIP
创建demoappv10资源
# kubectl apply -f deploy-demoapp-v10.yaml -f service-demoapp-v10.yaml
deployment.apps/demoappv10 created
service/demoappv10 created
查看demoappv10 pod
~# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
demoappv10-78b6586d58-css28 2/2 Running 0 55s app=demoapp,pod-template-hash=78b6586d58,security.istio.io/tlsMode=istio,service.istio.io/canonical-name=demoapp,service.istio.io/canonical-revision=v1.0,version=v1.0
demoappv10-78b6586d58-jmbwx 2/2 Running 0 55s app=demoapp,pod-template-hash=78b6586d58,security.istio.io/tlsMode=istio,service.istio.io/canonical-name=demoapp,service.istio.io/canonical-revision=v1.0,version=v1.0
部署demoappv1.1
deploy-demoapp-v11.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: demoappv11
version: v1.1
name: demoappv11
spec:
progressDeadlineSeconds: 600
replicas: 2
selector:
matchLabels:
app: demoapp
version: v1.1
template:
metadata:
labels:
app: demoapp
version: v1.1
spec:
containers:
- image: ikubernetes/demoapp:v1.1
imagePullPolicy: IfNotPresent
name: demoapp
env:
- name: "PORT"
value: "8080"
ports:
- containerPort: 8080
name: web
protocol: TCP
resources:
limits:
cpu: 50m
service-demoapp-v11.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: demoappv11
name: demoappv11
spec:
ports:
- name: http-8080
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: demoapp
version: v1.1
type: ClusterIP
创建demoappv11资源
# kubectl apply -f deploy-demoapp-v11.yaml -f service-demoapp-v11.yaml
deployment.apps/demoappv11 created
service/demoappv11 created
查看demoappv11 pod
~# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
demoappv10-78b6586d58-css28 2/2 Running 0 6m6s app=demoapp,pod-template-hash=78b6586d58,security.istio.io/tlsMode=istio,service.istio.io/canonical-name=demoapp,service.istio.io/canonical-revision=v1.0,version=v1.0
demoappv10-78b6586d58-jmbwx 2/2 Running 0 6m6s app=demoapp,pod-template-hash=78b6586d58,security.istio.io/tlsMode=istio,service.istio.io/canonical-name=demoapp,service.istio.io/canonical-revision=v1.0,version=v1.0
demoappv11-78bf898c74-l7sqg 2/2 Running 0 39s app=demoapp,pod-template-hash=78bf898c74,security.istio.io/tlsMode=istio,service.istio.io/canonical-name=demoapp,service.istio.io/canonical-revision=v1.1,version=v1.1
demoappv11-78bf898c74-x5ccw 2/2 Running 0 39s app=demoapp,pod-template-hash=78bf898c74,security.istio.io/tlsMode=istio,service.istio.io/canonical-name=demoapp,service.istio.io/canonical-revision=v1.1,version=v1.1
部署demoapp svc
service-demoapp.yaml
---
apiVersion: v1
kind: Service
metadata:
name: demoapp
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: demoapp
type: ClusterIP
---
创建service-demoapp资源
# kubectl apply -f service-demoapp.yaml
service/demoapp created
查看service-demoapp svc
~# kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
demoapp ClusterIP 10.100.193.250 <none> 8080/TCP 31s app=demoapp
demoappv10 ClusterIP 10.100.16.210 <none> 8080/TCP 8m54s app=demoapp,version=v1.0
demoappv11 ClusterIP 10.100.200.213 <none> 8080/TCP 3m28s app=demoapp,version=v1.1
部署proxy
deploy-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://demoapp: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 deploy-proxy.yaml
deployment.apps/proxy created
service/proxy created
查看proxy svc
~# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
demoapp ClusterIP 10.100.180.239 <none> 8080/TCP 35s
demoappv10 ClusterIP 10.100.174.88 <none> 8080/TCP 3m46s
demoappv11 ClusterIP 10.100.2.161 <none> 8080/TCP 76s
proxy ClusterIP 10.100.43.186 <none> 80/TCP 15s
测试访问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 #
访问应用
root@client # while true;do curl proxy/hostname; sleep 0.5; done
Proxying value: ServerName: demoappv11-78bf898c74-x5ccw
- Took 377 milliseconds.
Proxying value: ServerName: demoappv11-78bf898c74-l7sqg
- Took 25 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-jmbwx
- Took 51 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 30 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 7 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 16 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 6 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 5 milliseconds.
访问kiali
image image image image自定义route
查看demoapp routes
~# istioctl proxy-config routes demoappv11-78bf898c74-sn9qp
NAME DOMAINS MATCH VIRTUAL SERVICE
80 istio-egressgateway.istio-system, 10.100.121.95 /*
80 istio-ingressgateway.istio-system, 10.100.145.112 /*
80 proxy, proxy.default + 1 more... /*
80 tracing.istio-system, 10.100.92.199 /*
8080 demoapp, demoapp.default + 1 more... /*
8080 demoappv10, demoappv10.default + 1 more... /*
8080 demoappv11, demoappv11.default + 1 more... /*
9090 kiali.istio-system, 10.100.48.203 /*
9090 prometheus.istio-system, 10.100.42.102 /*
9411 jaeger-collector.istio-system, 10.100.122.235 /*
9411 zipkin.istio-system, 10.100.29.132 /*
15010 istiod.istio-system, 10.100.149.76 /*
15014 istiod.istio-system, 10.100.149.76 /*
16685 tracing.istio-system, 10.100.92.199 /*
20001 kiali.istio-system, 10.100.48.203 /*
istio-ingressgateway.istio-system.svc.cluster.local:15021 * /*
jaeger-collector.istio-system.svc.cluster.local:14268 * /*
kube-dns.kube-system.svc.cluster.local:9153 * /*
kubernetes-dashboard.kubernetes-dashboard.svc.cluster.local:443 * /*
grafana.istio-system.svc.cluster.local:3000 * /*
dashboard-metrics-scraper.kubernetes-dashboard.svc.cluster.local:8000 * /*
jaeger-collector.istio-system.svc.cluster.local:14250 * /*
inbound|8080|| * /*
InboundPassthroughClusterIpv4 * /*
* /healthz/ready*
* /stats/prometheus*
inbound|8080|| * /*
InboundPassthroughClusterIpv4 * /*
virtualservice-demoapp.yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: demoapp
spec:
hosts:
- demoapp
http:
- name: canary
match:
- uri:
prefix: /canary
rewrite:
uri: /
route:
- destination:
host: demoappv11
- name: default
route:
- destination:
host: demoappv10
创建资源
# kubectl apply -f virtualservice-demoapp.yaml
virtualservice.networking.istio.io/demoapp created
查看vs资源
~# kubectl get vs
NAME GATEWAYS HOSTS AGE
demoapp ["demoapp"] 52s
查看demoapp pod路由
~# istioctl proxy-config routes demoappv11-78bf898c74-sn9qp
NAME DOMAINS MATCH VIRTUAL SERVICE
80 demoapp.default.svc.cluster.local /canary* demoapp.default
80 demoapp.default.svc.cluster.local /* demoapp.default
80 istio-egressgateway.istio-system, 10.100.121.95 /*
80 istio-ingressgateway.istio-system, 10.100.145.112 /*
80 proxy, proxy.default + 1 more... /*
80 tracing.istio-system, 10.100.92.199 /*
8080 demoapp, demoapp.default + 1 more... /canary* demoapp.default
8080 demoapp, demoapp.default + 1 more... /* demoapp.default
8080 demoappv10, demoappv10.default + 1 more... /*
8080 demoappv11, demoappv11.default + 1 more... /*
9090 kiali.istio-system, 10.100.48.203 /*
9090 prometheus.istio-system, 10.100.42.102 /*
9411 jaeger-collector.istio-system, 10.100.122.235 /*
9411 zipkin.istio-system, 10.100.29.132 /*
15010 istiod.istio-system, 10.100.149.76 /*
15014 istiod.istio-system, 10.100.149.76 /*
16685 tracing.istio-system, 10.100.92.199 /*
20001 kiali.istio-system, 10.100.48.203 /*
istio-ingressgateway.istio-system.svc.cluster.local:15021 * /*
jaeger-collector.istio-system.svc.cluster.local:14268 * /*
kube-dns.kube-system.svc.cluster.local:9153 * /*
kubernetes-dashboard.kubernetes-dashboard.svc.cluster.local:443 * /*
grafana.istio-system.svc.cluster.local:3000 * /*
dashboard-metrics-scraper.kubernetes-dashboard.svc.cluster.local:8000 * /*
jaeger-collector.istio-system.svc.cluster.local:14250 * /*
inbound|8080|| * /*
InboundPassthroughClusterIpv4 * /*
* /healthz/ready*
* /stats/prometheus*
inbound|8080|| * /*
InboundPassthroughClusterIpv4 * /*
访问demoapp
访问defalut
root@client # while true;do curl proxy/hostname; sleep 0.5; done
Proxying value: ServerName: demoappv10-78b6586d58-jmbwx
- Took 32 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 14 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 4 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-jmbwx
- Took 5 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 10 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 5 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-css28
- Took 5 milliseconds.
Proxying value: ServerName: demoappv10-78b6586d58-jmbwx
- Took 5 milliseconds.
查看kiali
image访问canary
root@client # while true;do curl proxy/canary; sleep 0.5; done
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 46 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 18 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-n88v6, ServerIP: 172.20.154.237!
- Took 38 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-n88v6, ServerIP: 172.20.154.237!
- Took 5 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 5 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-n88v6, ServerIP: 172.20.154.237!
- Took 12 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 7 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 5 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-n88v6, ServerIP: 172.20.154.237!
- Took 4 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 5 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 4 milliseconds.
Proxying value: iKubernetes demoapp v1.1 !! ClientIP: 127.0.0.6, ServerName: demoappv11-78bf898c74-zzcpv, ServerIP: 172.20.44.249!
- Took 10 milliseconds.
网友评论