标签:ons set tar pac replace affinity -name lazy route
文章主要介绍如何把一个简单的HelloWebApp装在Istio+K8S环境下
下面是基本步骤:
前三点不在本文介绍,从第四点介绍
在k8s,可以在整个Namespace enable sidecar后, 在Deployment YAML加上下面的annotation, 当Create POD时会自动加上Sidecar container. 我的测试环境中,整个Namespace没有enable istio, 所以我用了命令行的方式,下载istio-1.8.3-win,在Bin目录下有个istioctl.exe, 配置到环境变量path中,运行:
kubectl get deployment hello -n ns -o yaml | istioctl kube-inject -f - | kubectl apply -f -
执行完之后kubectl get pods 查看该POD有两个Container,表明Sidecar enalbe 成功,如果命令执行失败,要核实K8S上的Istio与Istioctl Command的版本号,要保持一致。
Istioctl
template:
metadata:
annotations:
sidecar.istio.io/inject: "true"
前提: 在istio-system name空间有相应的istio-ingressgateway的pod与Service,注意istio-ingressgateway service是有External-IP的,这样可以把ServiceMesh中的服务暴露到外面。


kind: Service
apiVersion: v1
metadata:
name: istio-ingressgateway-delegate
namespace: mynamespace
spec:
type: ExternalName
sessionAffinity: None
externalName: istio-ingressgateway.istio-system.svc.cluster.local
ports:
- name: http
port: 80
targetPort: 80
test.vt.xx.net : 这个域名是暴露到外面的域名
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway-mynamespace
namespace: mynamespace
spec:
selector:
istio: ingressgateway
servers:
- port:
name: http
number: 80
protocol: HTTP
hosts:
- "test.vt.xx.net"
注意:Host的配置与2.2一致,gateways 的配置与2.2 中name一致。这两个字段标识了VirtualService帮定的网关, destination host 指向了k8s Service的集群内地址。
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: mynamespace-vs-external
namespace: sqo
spec:
hosts:
- test.vt.xx.net
gateways:
- gateway-my-namespace
http:
- match:
- uri:
prefix: "/web/hello"
route:
- destination:
host: hello.mynamespace.svc.cluster.local
port:
number: 9080
subset: stable
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: hello-vs
namespace: mynamespace
spec:
hosts:
- hello.mynamespace.svc.cluster.local
http:
- route:
- destination:
host: hello.mynamespace.svc.cluster.local
port:
number: 9080
subset: stable
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: hello-dr
namespace: mynamespace
spec:
host: hello.mynamespace.svc.cluster.local
trafficPolicy:
loadBalancer:
simple: ROUND_ROBIN
subsets:
- name: stable
labels:
version: new-app-version-replace
K8s + istio 之 Gataway, VirtualService, DestinationRule
标签:ons set tar pac replace affinity -name lazy route
原文地址:https://www.cnblogs.com/Ivyduan/p/14593656.html