istio-1.12.0-部署


一,k8s安装istio

https://github.com/istio/istio/releases/istio-1.12.0-linux-amd64.tar.gz

root@master001:~/istio/istio-1.12.0/bin# cp -a istioctl /usr/bin/

root@master001:~/istio-1.12.0# istioctl install --set profile=demo
This will install the Istio 1.12.0 demo profile with ["Istio core" "Istiod" "Ingress gateways" "Egress gateways"] components into the cluster. Proceed? (y/N) y

root@slave001:~# docker images |grep istio
istio/proxyv2:1.12.0
istio/pilot:1.12.0

root@slave001:~# kubectl get po -A
NAMESPACE      NAME                                       READY   STATUS    RESTARTS   AGE
istio-system   istio-egressgateway-7f4864f59c-nz69w       1/1     Running   0          9m48s
istio-system   istio-ingressgateway-55d9fb9f-trmkq        1/1     Running   0          9m29s
istio-system   istiod-555d47cb65-dlfs4                    1/1     Running   0          24m
root@master001:~/istio/istio-1.12.0/bin# kubectl get svc -n istio-system
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                     AGE
istio-egressgateway    ClusterIP      10.100.185.189           80/TCP,443/TCP                                                              28m
istio-ingressgateway   LoadBalancer   10.100.94.111         15021:60211/TCP,80:57328/TCP,443:61049/TCP,31400:2464/TCP,15443:59853/TCP   28m
istiod                 ClusterIP      10.100.136.217           15010/TCP,15012/TCP,443/TCP,15014/TCP                                       29m

 二,Istio部署在线书店bookinfo

root@master001:~# kubectl label namespace default istio-injection=enabled
root@master001:~/istio/istio-1.12.0# kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml

 镜像

docker.io/istio/examples-bookinfo-details-v1:1.16.2

docker.io/istio/examples-bookinfo-productpage-v1:1.16.2

docker.io/istio/examples-bookinfo-ratings-v1:1.16.2

docker.io/istio/examples-bookinfo-reviews-v1:1.16.2
docker.io/istio/examples-bookinfo-reviews-v2:1.16.2
docker.io/istio/examples-bookinfo-reviews-v3:1.16.2

root@slave001:~/bookinfo# kubectl get po
NAME                              READY   STATUS    RESTARTS   AGE
details-v1-79f774bdb9-zdmwn       2/2     Running   0          50m
productpage-v1-6b746f74dc-g6tgw   2/2     Running   0          50m
ratings-v1-b6994bb9-gtv7t         2/2     Running   0          50m
reviews-v1-545db77b95-k4tfn       2/2     Running   0          12m
reviews-v2-7bf8c9648f-p7mc6       2/2     Running   0          8m20s
reviews-v3-84779c7bbc-fb5bq       2/2     Running   0          119s

 确认运行正常

root@slave001:~# kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o ".*"
Simple Bookstore App

1,为应用程序定义gateway网关

root@master001:~/istio/istio-1.12.0# cat samples/bookinfo/networking/bookinfo-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: bookinfo-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bookinfo
spec:
  hosts:
  - "*"
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        prefix: /static
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    route:
    - destination:
        host: productpage
        port:
          number: 9080
root@master001:~/istio/istio-1.12.0# kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
root@master001:~/istio/istio-1.12.0# kubectl get gateway
NAME               AGE
bookinfo-gateway   12s
root@master001:~/istio/istio-1.12.0# kubectl get virtualservice
NAME       GATEWAYS               HOSTS   AGE
bookinfo   ["bookinfo-gateway"]   ["*"]   20s

2,确定ingress ip和端口

root@master001:~/istio/istio-1.12.0# kubectl get svc istio-ingressgateway -n istio-system
NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                                     AGE
istio-ingressgateway   LoadBalancer   10.100.94.111        15021:60211/TCP,80:57328/TCP,443:61049/TCP,31400:2464/TCP,15443:59853/TCP   22h

3,获取Istio Gateway的地址

root@master001:~/istio/istio-1.12.0# kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}'
57328
root@master001:
~/istio/istio-1.12.0# export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}') root@master001:~/istio/istio-1.12.0# echo $INGRESS_PORT 57328
root@master001:~/istio/istio-1.12.0# export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
root@master001:~/istio/istio-1.12.0# echo $SECURE_INGRESS_PORT
61049

 设置gateway url

root@master001:~/istio/istio-1.12.0# INGRESS_HOST=192.168.192.151
root@master001:~/istio/istio-1.12.0#  export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
root@master001:~/istio/istio-1.12.0# echo $GATEWAY_URL
192.168.192.151:57328

4,使用curl命令确认能从集群外部访问bookinfo应用程序

root@master001:~/istio/istio-1.12.0# curl -s http://${GATEWAY_URL}/productpage | grep -o ".*"
Simple Bookstore App

浏览器访问http://192.168.192.151:57328/productpage

5,扩展:添加外部IP-extertal-IP

spec:
  clusterIP: 10.100.94.111
  clusterIPs:
  - 10.100.94.111
  externalIPs:
  - 192.168.192.151

6,卸载bookinfo服务

# 1.删除路由规则,并销毁应用的 Pod

root@master001:~/istio/istio-1.12.0# bash samples/bookinfo/platform/kube/cleanup.sh
namespace ? [default] y
NAMESPACE y not found.
using NAMESPACE=default

            #delete yaml文件也可

# 2.确认应用已经关停
kubectl get virtualservices     #-- there should be no virtual services
kubectl get destinationrules   #-- there should be no destination rules
kubectl get gateway           #-- there should be no gateway
kubectl get pods               #-- the Bookinfo pods should be deleted

 三,Istio实现灰度发布

金丝雀部署 新老版本逐步交替

root@master001:~/istio-canary# cat deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: appv1
  labels:
    app: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: v1
      apply: canary
  template:
    metadata:
      labels:
        app: v1
        apply: canary
    spec:
      containers:
      - name: nginx
        image: xianchao/canary:v1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: appv2
  labels:
    app: v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: v2
      apply: canary
  template:
    metadata:
      labels:
        app: v2
        apply: canary
    spec:
      containers:
      - name: nginx
        image: xianchao/canary:v2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
root@master001:~/istio-canary# cat service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: canary
  labels:
    apply: canary
spec:
  selector:
    apply: canary
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
root@master001:~/istio-canary# cat gateway.yaml 
apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: canary-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
root@master001:~/istio-canary# cat virtual.yaml 
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: canary
spec:
  hosts:
  - "*"
  gateways:
  - canary-gateway
  http:
  - route:
    - destination:
        host: canary.default.svc.cluster.local
        subset: v1
      weight: 90
    - destination:
        host: canary.default.svc.cluster.local
        subset: v2
      weight: 10
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
  name: canary
spec:
  host: canary.default.svc.cluster.local
  subsets:
  - name: v1
    labels:
      app: v1
  - name: v2
    labels:
      app: v2
root@master001:~/istio-canary# kubectl get gateway
NAME             AGE
canary-gateway   7m55s
root@master001:~/istio-canary# kubectl get virtualservices
NAME     GATEWAYS             HOSTS   AGE
canary   ["canary-gateway"]   ["*"]   5m53s

验证效果

kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}'
for i in `seq 1 100`; do curl 192.168.192.151:57328;done > 1.txt

 

相关