首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Istio直接Pod到Pod通信

Istio直接Pod到Pod通信
EN

Stack Overflow用户
提问于 2019-04-01 12:48:45
回答 2查看 5.6K关注 0票数 4

我对用Istio部署的Pod和Pod的通信有问题吗?我实际上需要它用于让黑兹尔卡斯特发现公司与Istio合作,但我将尝试在这里概括这个问题。

让我们在Kubernetes上部署一个示例hello world服务。该服务响应端口8000上的HTTP请求。

代码语言:javascript
复制
$ kubectl create deployment nginx --image=crccheck/hello-world

创建的Pod有一个内部IP分配:

代码语言:javascript
复制
$ kubectl get pods -o wide
NAME                               READY   STATUS    RESTARTS   AGE   IP           NODE                                                  NOMINATED NODE
hello-deployment-84d876dfd-s6r5w   1/1     Running   0          8m    10.20.3.32   gke-rafal-test-istio-1-0-default-pool-91f437a3-cf5d   <none>

在作业curl.yaml中,我们可以直接使用Pod。

代码语言:javascript
复制
apiVersion: batch/v1
kind: Job
metadata:
  name: curl
spec:
  template:
    spec:
      containers:
      - name: curl
        image: byrnedo/alpine-curl
        command: ["curl",  "10.20.3.32:8000"]
      restartPolicy: Never
  backoffLimit: 4

在没有Istio的情况下运行这项工作很好。

代码语言:javascript
复制
$ kubectl apply -f curl.yaml
$ kubectl logs pod/curl-pptlm
...
Hello World
...

然而,当我试图对Istio做同样的事情时,它就不起作用了。特使阻止HTTP请求。

代码语言:javascript
复制
$ kubectl apply -f <(istioctl kube-inject -f curl.yaml)
$ kubectl logs pod/curl-s2bj6 curl
...
curl: (7) Failed to connect to 10.20.3.32 port 8000: Connection refused

我玩过服务条目、MESH_INTERNAL和MESH_EXTERNAL,但没有成功。如何绕过特使,直接打电话到Pod?

编辑:istioctl kube-inject -f curl.yaml输出。

代码语言:javascript
复制
$ istioctl kube-inject -f curl.yaml
apiVersion: batch/v1
kind: Job
metadata:
  creationTimestamp: null
  name: curl
spec:
  backoffLimit: 4
  template:
    metadata:
      annotations:
        sidecar.istio.io/status: '{"version":"dbf2d95ff300e5043b4032ed912ac004974947cdd058b08bade744c15916ba6a","initContainers":["istio-init"],"containers":["istio-proxy"],"volumes":["istio-envoy","istio-certs"],"imagePullSecrets":null}'
      creationTimestamp: null
    spec:
      containers:
      - command:
        - curl
        - 10.16.2.34:8000/
        image: byrnedo/alpine-curl
        name: curl
        resources: {}
      - args:
        - proxy
        - sidecar
        - --domain
        - $(POD_NAMESPACE).svc.cluster.local
        - --configPath
        - /etc/istio/proxy
        - --binaryPath
        - /usr/local/bin/envoy
        - --serviceCluster
        - curl.default
        - --drainDuration
        - 45s
        - --parentShutdownDuration
        - 1m0s
        - --discoveryAddress
        - istio-pilot.istio-system:15010
        - --zipkinAddress
        - zipkin.istio-system:9411
        - --connectTimeout
        - 10s
        - --proxyAdminPort
        - "15000"
        - --concurrency
        - "2"
        - --controlPlaneAuthPolicy
        - NONE
        - --statusPort
        - "15020"
        - --applicationPorts
        - ""
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: INSTANCE_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: ISTIO_META_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: ISTIO_META_CONFIG_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: ISTIO_META_INTERCEPTION_MODE
          value: REDIRECT
        image: docker.io/istio/proxyv2:1.1.1
        imagePullPolicy: IfNotPresent
        name: istio-proxy
        ports:
        - containerPort: 15090
          name: http-envoy-prom
          protocol: TCP
        readinessProbe:
          failureThreshold: 30
          httpGet:
            path: /healthz/ready
            port: 15020
          initialDelaySeconds: 1
          periodSeconds: 2
        resources:
          limits:
            cpu: "2"
            memory: 128Mi
          requests:
            cpu: 100m
            memory: 128Mi
        securityContext:
          readOnlyRootFilesystem: true
          runAsUser: 1337
        volumeMounts:
        - mountPath: /etc/istio/proxy
          name: istio-envoy
        - mountPath: /etc/certs/
          name: istio-certs
          readOnly: true
      initContainers:
      - args:
        - -p
        - "15001"
        - -u
        - "1337"
        - -m
        - REDIRECT
        - -i
        - '*'
        - -x
        - ""
        - -b
        - ""
        - -d
        - "15020"
        image: docker.io/istio/proxy_init:1.1.1
        imagePullPolicy: IfNotPresent
        name: istio-init
        resources:
          limits:
            cpu: 100m
            memory: 50Mi
          requests:
            cpu: 10m
            memory: 10Mi
        securityContext:
          capabilities:
            add:
            - NET_ADMIN
      restartPolicy: Never
      volumes:
      - emptyDir:
          medium: Memory
        name: istio-envoy
      - name: istio-certs
        secret:
          optional: true
          secretName: istio.default
status: {}
---
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-15 06:00:20

当一个带有坐式汽车的吊舱启动时,事情就会发生。

  1. init容器更改iptables规则,以便将所有传出的tcp流量路由到端口15001上的sidecar容器(Istio)。
  2. 吊舱的容器是并行启动的(curlistio-proxy)

如果您的curl容器是在istio-proxy侦听端口15001之前执行的,则会得到错误。

我使用sleep命令启动这个容器,exec-d进入容器,而curl工作。

代码语言:javascript
复制
$ kubectl apply -f <(istioctl kube-inject -f curl-pod.yaml)

$ k exec -it -n noistio curl -c curl bash
[root@curl /]# curl 172.16.249.198:8000
<xmp>
Hello World


                                       ##         .
                                 ## ## ##        ==
                              ## ## ## ## ##    ===
                           /""""""""""""""""\___/ ===
                      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
                           \______ o          _,/
                            \      \       _,'
                             `'--.._\..--''
</xmp>
[root@curl /]# 

curl-pod.yaml

代码语言:javascript
复制
apiVersion: v1
kind: Pod
metadata:
  name: curl
spec:
  containers:
  - name: curl
    image: centos
    command: ["sleep",  "3600"]
票数 4
EN

Stack Overflow用户

发布于 2019-05-21 22:29:10

确保您已经配置了一个入口“网关”,然后您需要配置一个"VirtualService“。有关简单示例,请参阅下面的链接。

https://istio.io/docs/tasks/traffic-management/ingress/#configuring-ingress-using-an-istio-gateway

一旦您部署了网关和虚拟服务,您就应该能够从外部'curl‘您的服务,该集群来自外部IP。

但是,如果要检查集群中的中的通信量,则需要使用istio的镜像API将服务( pod )从一个吊舱镜像到另一个吊舱,然后使用命令(kubectl apply -f curl.yaml)查看流量。

有关镜像示例,请参阅下面的链接:

https://istio.io/docs/tasks/traffic-management/mirroring/

希望这能帮上忙

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55455523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档