让OpenShift Serivce Mesh自动对服务注入sidecar

36 篇文章 0 订阅
34 篇文章 1 订阅

和Istio稍有不同,OpenShift Service Mesh缺省不会自动对服务注入sidecar容器。以istio的helloworld为例,在执行以下命令后,每个Pod只运行了一个容器,并没有自动注入对应的sidecar容器。

$ oc create -f https://raw.githubusercontent.com/istio/istio/master/samples/helloworld/helloworld.yaml
$ oc get pod
NAME                             READY   STATUS    RESTARTS   AGE
helloworld-v1-7bb88866c4-kd4jj   1/1     Running   0          3m32s
helloworld-v2-6cd449dff4-xtf2n   1/1     Running   0          3m32s

为了实现自动sidecar容器注入,只需要在Deployment定义中增加以下内容即可:

  annotations:
    sidecar.istio.io/inject: "true"

例如上述helloworld.yaml,将其下载然后修改为以下内容:

apiVersion: v1
kind: Service
metadata:
  name: helloworld
  labels:
    app: helloworld
spec:
  ports:
  - port: 5000
    name: http
  selector:
    app: helloworld
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-v1
  labels:
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
      version: v1
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        app: helloworld
        version: v1
    spec:
      containers:
      - name: helloworld
        image: docker.io/istio/examples-helloworld-v1
        resources:
          requests:
            cpu: "100m"
        imagePullPolicy: IfNotPresent #Always
        ports:
        - containerPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-v2
  labels:
    version: v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
      version: v2
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "true"
      labels:
        app: helloworld
        version: v2
    spec:
      containers:
      - name: helloworld
        image: docker.io/istio/examples-helloworld-v2
        resources:
          requests:
            cpu: "100m"
        imagePullPolicy: IfNotPresent #Always
        ports:
        - containerPort: 5000

当OpenShift配置Service Mesh Plane后执行命令创建微服务,可以看到OpenShift可以自动生成注入sidecar容器了。

$ oc create -f helloworld.yaml
$ oc get pod
NAME                             READY   STATUS    RESTARTS   AGE
helloworld-v1-54fd8d846-7jklf    2/2     Running   0          16m
helloworld-v2-576ccf4654-94vkb   2/2     Running   0          18m
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值