百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

istio的安装与使用(istio1.8安装)

itomcoil 2025-04-01 19:01 13 浏览

1.安装istio

a 下载istioctl安装

下载
$ wget https://github.com/istio/istio/releases/download/1.7.3/istio-1.7.3-linux-amd64.tar.gz
配置
tar zxf istio-1.7.3-linux-amd64.tar.gz
cd istio-1.7.3 && cp bin/istioctl /usr/local/bin

b.安装iostio

#指定下载的镜像地址进行安装
istioctl install --set profile=demo --set values.pilot.image="harbor.assistfc.com/middleware/pilot:1.7.3" --set values.proxy.image="harbor.assistfc.com/middleware/proxyv2:1.7.3"
#效果如下
root@test-k8s-master1:~# kubectl get pod -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE
istio-egressgateway-7f6bd48c74-t9q6g    1/1     Running   0          6m16s
istio-ingressgateway-69f5465fff-szfql   1/1     Running   0          6m16s
istiod-7c57888-65564                    1/1     Running   0          6m26s

c查看

# 查看提供的profile类型
$ istioctl profile list

# 获取kubernetes的yaml:
$ istioctl manifest generate --set profile=demo > istio-kubernetes-manifest.yaml  #可查看要安装镜像image

d 卸载命令

$ istioctl manifest generate --set profile=demo | kubectl delete -f -

实践网络分流的权重

1.资源清单

后端服务

#后端一
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    service: bill-service
    version: v1
  name: bill-service-v1
  namespace: istio-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      service: bill-service
      version: v1
  template:
    metadata:
      labels:
        service: bill-service
        version: v1
    spec:
      containers:
      - image: harbor.assistfc.com/middleware/nginx:alpine
        name: bill-service
        command: ["/bin/sh", "-c", "echo 'this is bill-service-v1'>/usr/share/nginx/html/index.html;nginx -g 'daemon off;'"]
#后端2
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    service: bill-service
    version: v2
  name: bill-service-v2
  namespace: istio-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      service: bill-service
      version: v2
  template:
    metadata:
      labels:
        service: bill-service
        version: v2
    spec:
      containers:
      - image: harbor.assistfc.com/middleware/nginx:alpine
        name: bill-service
        command: ["/bin/sh", "-c", "echo 'this is bill-service-v2'>/usr/share/nginx/html/index.html;nginx -g 'daemon off;'"]
#service   %50均分流量

apiVersion: v1
kind: Service
metadata:
  labels:
    service: bill-service
  name: bill-service
  namespace: istio-demo
spec:
  ports:
  - name: http
    port: 9999
    protocol: TCP
    targetPort: 80
  selector:
    service: bill-service
  type: ClusterIP

#实现90%的流量 到v1 10%到v2

需要通过istio的两个新的资源类型:VirtualServiceDestinationRule实现

具体如下

使用Istio 注入sidecar

$ istioctl kube-inject -f service-tomecat-v2.yaml|kubectl apply -f -
$ istioctl kube-inject -f service-tomecat-v1.yaml|kubectl apply -f -
$ istioctl kube-inject -f front-tomecat.yaml|kubectl apply -f -

注入网络接管服务 proxyv2:1.7.3

查看容器的状态

#会启动新的容器
root@test-k8s-master1:~/istio-demo# kubectl get pod -n istio-demo
NAME                               READY   STATUS    RESTARTS   AGE
bill-service-v1-86754676d6-qcstq   2/2     Running   0          86m
bill-service-v2-777d8d98c7-gzhth   2/2     Running   0          85m
front-tomcat-v1-9c866f69b-m56kw    2/2     Running   0          88m

#配置destination文件和vertuleservice

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: dest-bill-service
  namespace: istio-demo
spec:
  host: bill-service
  subsets:
  - name: v1
    labels:
      version: v1
  - name: v2
    labels:
      version: v2
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: vs-bill-service
  namespace: istio-demo
spec:
  hosts:
  - bill-service
  http:
  - name: bill-service-route
    route:
    - destination:
        host: bill-service
        subset: v1
      weight: 90
    - destination:
        host: bill-service
        subset: v2
      weight: 10
ervice:9999
this is bill-service-v1
root@test-k8s-master1:~/istio-demo# kubectl exec -it front-tomcat-v1-9c866f69b-m56kw  -n istio-demo -c front-tomcat  -- curl -s bill-service:9999
this is bill-service-v1
root@test-k8s-master1:~/istio-demo# kubectl exec -it front-tomcat-v1-9c866f69b-m56kw  -n istio-demo -c front-tomcat  -- curl -s bill-service:9999
this is bill-service-v1
root@test-k8s-master1:~/istio-demo# kubectl exec -it front-tomcat-v1-9c866f69b-m56kw  -n istio-demo -c front-tomcat  -- curl -s bill-service:9999
this is bill-service-v2
root@test-k8s-master1:~/istio-demo# kubectl exec -it front-tomcat-v1-9c866f69b-m56kw  -n istio-demo -c front-tomcat  -- curl -s bill-service:9999
this is bill-service-v1

以上为测试结果实现90%和10%的流量的切换

相关推荐

CentOS7服务器,这样搭建Tensorflow很快!我可以提前去吃饭了

CentOS7搭建Tensorflow框架凡是我相信的,我都做了;凡是我做了的事,都是全身心地投入去做的。WhateverIbelieved,Idid;andwhateverIdid,...

python2.0和python3.0的区别(python2.7和3.7哪个好)

Python3.0是Python语言的一次重大升级,与Python2.x系列存在许多不兼容的改动。以下是两者核心区别的全面总结,按重要性和使用频率排序:一、最关键的破坏性变更特性Pyth...

体验无GIL的自由线程Python:Python 3.13 新特征之一

全局解释器锁(GIL,GlobalInterpreterLock)是Python中备受争议的特性之一。它的主要作用是确保Python是一种线程安全的编程语言,防止多个线程同时访问和修改同一...

Python 3.8异步并发编程指南(python异步调用)

有效的提高程序执行效率的两种方法是异步和并发,Golang,node.js之所以可以有很高执行效率主要是他们的协程和异步并发机制。实际上异步和并发是每一种现代语言都在追求的特性,当然Python也不例...

Python测试框架pytest入门基础(pytest框架搭建)

Pytest简介Pytestisamaturefull-featuredPythontestingtoolthathelpsyouwritebetterprograms.T...

Python学不会来打我(8)字符串string类型深度解析

2025年全球开发者调查显示,90%的Python项目涉及字符串处理,而高效使用字符串可提升代码效率40%。本文系统拆解字符串核心操作,涵盖文本处理、数据清洗、模板生成等八大场景,助你掌握字符串编程精...

windows使用pyenv安装多python版本环境

官方的介绍。pyenvletsyoueasilyswitchbetweenmultipleversionsofPython.It’ssimple,unobtrusive,an...

Python 中 base64 编码与解码(Python 中 base64 编码与解码生成)

base64是经常使用的一种加密方式,在Python中有专门的库支持。本文主要介绍在Python2和Python3中的使用区别:在Python2环境:Python2.7.16(d...

Python项目整洁的秘诀:深入理解__init__.py文件

当你发现项目中import语句越来越混乱时,问题可能出在缺少这个关键文件上作为一名Python开发者,我曾深陷项目结构混乱的困境。直到真正理解了__init__.py文件的价值,我的代码世界才变得井然...

如何把一个Python应用程序装进Docker

准备容器无处不在,但是如何在Docker容器中运行Python应用程序呢?这篇文章将告诉你怎么做!如果您想知道,这些示例需要Python3.x。在深入讨论容器之前,让我们进一步讨论一下我们想要封装的...

python中数值比较大小的8种经典比较方法,不允许你还不知道

在Python中比较数值大小是基础但重要的操作。以下是8种经典比较方法及其应用场景,从基础到进阶的完整指南:1.基础比较运算符Python提供6种基础比较运算符:a,b=5,3...

Python程序员必看3分钟掌握if语句10个神技,第5个99%的人不知道

同事因为写错一个if被开除?全网疯传的Python避坑指南,看完我连夜改了代码!一、新手必踩的3大天坑(附救命代码)技巧1:缩进踩坑事件ifTrue:print("这样写必报错!...

为什么Python里遍历字符串比列表慢?3个底层原因揭秘

用字符串处理文本时,你可能正悄悄浪费性能。在日常Python开发中,我们经常需要遍历字符串和列表。但你是否注意过,当处理海量数据时,遍历字符串的速度明显比列表慢?这背后隐藏着Python设计的深层逻辑...

记录Python3.7.4更新到Python.3.7.8

Python官网Python安装包下载下载文件名称运行后选择升级选项等待安装安装完毕打开IDLE使用Python...

Python3中最常用的5种线程锁你会用吗

前言本章节将继续围绕threading模块讲解,基本上是纯理论偏多。对于日常开发者来讲很少会使用到本章节的内容,但是对框架作者等是必备知识,同时也是高频的面试常见问题。私信小编01即可获取大量Pyth...