Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes POD之间的通信_Kubernetes_Openshift_Sentry - Fatal编程技术网

Kubernetes POD之间的通信

Kubernetes POD之间的通信,kubernetes,openshift,sentry,Kubernetes,Openshift,Sentry,我目前正在进行设置,但在openshift 3.11中设置时遇到问题 我得到了运行sentry本身、postgresql、redis和memcache的吊舱,但根据日志消息,它们无法一起通信 sentry.exceptions.InvalidConfiguration: Error 111 connecting to 127.0.0.1:6379. Connection refused. 我是否需要像docker那样创建一个网络,或者POD(都在同一个名称空间中)在默认情况下应该能够相互通信?

我目前正在进行设置,但在openshift 3.11中设置时遇到问题

我得到了运行
sentry
本身、
postgresql
redis
memcache
的吊舱,但根据日志消息,它们无法一起通信

sentry.exceptions.InvalidConfiguration: Error 111 connecting to 127.0.0.1:6379. Connection refused.
我是否需要像docker那样创建一个网络,或者POD(都在同一个名称空间中)在默认情况下应该能够相互通信?我获得了整个项目的管理员权限,因此我还可以使用控制台,而不仅仅是web界面

祝福

编辑:为sentry及其服务添加部署配置,并为简单起见添加postgres配置和服务。我还用关键字
BLANK
删除了一些不必要的信息。如果我太过火了,请告诉我,我会查一下

哨兵的部署配置:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  generation: 20
  labels:
    app: sentry
  name: sentry
  namespace: test
  resourceVersion: '506667843'
  selfLink: BLANK
  uid: BLANK
spec:
  replicas: 1
  selector:
    app: sentry
    deploymentconfig: sentry
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      annotations:
        openshift.io/generated-by: OpenShiftWebConsole
      creationTimestamp: null
      labels:
        app: sentry
        deploymentconfig: sentry
    spec:
      containers:
        - env:
            - name: SENTRY_SECRET_KEY
              value: Iamsosecret
            - name: C_FORCE_ROOT
              value: '1'
            - name: SENTRY_FILESTORE_DIR
              value: /var/lib/sentry/files/data
          image: BLANK
          imagePullPolicy: Always
          name: sentry
          ports:
            - containerPort: 9000
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /var/lib/sentry/files
              name: sentry-1
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - emptyDir: {}
          name: sentry-1
  test: false
  triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
          - sentry
        from:
          kind: ImageStreamTag
          name: 'sentry:latest'
          namespace: catcloud
        lastTriggeredImage: BLANK
      type: ImageChange
status:
  availableReplicas: 1
  conditions:
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: Deployment config has minimum availability.
      status: 'True'
      type: Available
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: replication controller "sentry-19" successfully rolled out
      reason: NewReplicationControllerAvailable
      status: 'True'
      type: Progressing
  details:
    causes:
      - type: ConfigChange
    message: config change
  latestVersion: 19
  observedGeneration: 20
  readyReplicas: 1
  replicas: 1
  unavailableReplicas: 0
  updatedReplicas: 1
apiVersion: v1
kind: Service
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  labels:
    app: sentry
  name: sentry
  namespace: test
  resourceVersion: '505555608'
  selfLink: BLANK
  uid: BLANK
spec:
  clusterIP: BLANK
  ports:
    - name: 9000-tcp
      port: 9000
      protocol: TCP
      targetPort: 9000
  selector:
    deploymentconfig: sentry
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
哨兵服务:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  generation: 20
  labels:
    app: sentry
  name: sentry
  namespace: test
  resourceVersion: '506667843'
  selfLink: BLANK
  uid: BLANK
spec:
  replicas: 1
  selector:
    app: sentry
    deploymentconfig: sentry
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      annotations:
        openshift.io/generated-by: OpenShiftWebConsole
      creationTimestamp: null
      labels:
        app: sentry
        deploymentconfig: sentry
    spec:
      containers:
        - env:
            - name: SENTRY_SECRET_KEY
              value: Iamsosecret
            - name: C_FORCE_ROOT
              value: '1'
            - name: SENTRY_FILESTORE_DIR
              value: /var/lib/sentry/files/data
          image: BLANK
          imagePullPolicy: Always
          name: sentry
          ports:
            - containerPort: 9000
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /var/lib/sentry/files
              name: sentry-1
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - emptyDir: {}
          name: sentry-1
  test: false
  triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
          - sentry
        from:
          kind: ImageStreamTag
          name: 'sentry:latest'
          namespace: catcloud
        lastTriggeredImage: BLANK
      type: ImageChange
status:
  availableReplicas: 1
  conditions:
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: Deployment config has minimum availability.
      status: 'True'
      type: Available
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: replication controller "sentry-19" successfully rolled out
      reason: NewReplicationControllerAvailable
      status: 'True'
      type: Progressing
  details:
    causes:
      - type: ConfigChange
    message: config change
  latestVersion: 19
  observedGeneration: 20
  readyReplicas: 1
  replicas: 1
  unavailableReplicas: 0
  updatedReplicas: 1
apiVersion: v1
kind: Service
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  labels:
    app: sentry
  name: sentry
  namespace: test
  resourceVersion: '505555608'
  selfLink: BLANK
  uid: BLANK
spec:
  clusterIP: BLANK
  ports:
    - name: 9000-tcp
      port: 9000
      protocol: TCP
      targetPort: 9000
  selector:
    deploymentconfig: sentry
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
postgresql
的部署配置:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  generation: 10
  labels:
    app: postgres
    type: backend
  name: postgres
  namespace: test
  resourceVersion: '506664185'
  selfLink: BLANK
  uid: BLANK
spec:
  replicas: 1
  selector:
    app: postgres
    deploymentconfig: postgres
    type: backend
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      annotations:
        openshift.io/generated-by: OpenShiftWebConsole
      creationTimestamp: null
      labels:
        app: postgres
        deploymentconfig: postgres
        type: backend
    spec:
      containers:
        - env:
            - name: PGDATA
              value: /var/lib/postgresql/data/sql
            - name: POSTGRES_HOST_AUTH_METHOD
              value: trust
            - name: POSTGRESQL_USER
              value: sentry
            - name: POSTGRESQL_PASSWORD
              value: sentry
            - name: POSTGRESQL_DATABASE
              value: sentry
          image: BLANK
          imagePullPolicy: Always
          name: postgres
          ports:
            - containerPort: 5432
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: volume-uirge
              subPath: sql
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        runAsUser: 2000020900
      terminationGracePeriodSeconds: 30
      volumes:
        - name: volume-uirge
          persistentVolumeClaim:
            claimName: postgressql
  test: false
  triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
          - postgres
        from:
          kind: ImageStreamTag
          name: 'postgres:latest'
          namespace: catcloud
        lastTriggeredImage: BLANK
      type: ImageChange
status:
  availableReplicas: 1
  conditions:
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: Deployment config has minimum availability.
      status: 'True'
      type: Available
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: replication controller "postgres-9" successfully rolled out
      reason: NewReplicationControllerAvailable
      status: 'True'
      type: Progressing
  details:
    causes:
      - type: ConfigChange
    message: config change
  latestVersion: 9
  observedGeneration: 10
  readyReplicas: 1
  replicas: 1
  unavailableReplicas: 0
  updatedReplicas: 1
apiVersion: v1
kind: Service
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  labels:
    app: postgres
    type: backend
  name: postgres
  namespace: catcloud
  resourceVersion: '506548841'
  selfLink: /api/v1/namespaces/catcloud/services/postgres
  uid: BLANK
spec:
  clusterIP: BLANK
  ports:
    - name: 5432-tcp
      port: 5432
      protocol: TCP
      targetPort: 5432
  selector:
    deploymentconfig: postgres
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
服务配置
postgresql

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  generation: 10
  labels:
    app: postgres
    type: backend
  name: postgres
  namespace: test
  resourceVersion: '506664185'
  selfLink: BLANK
  uid: BLANK
spec:
  replicas: 1
  selector:
    app: postgres
    deploymentconfig: postgres
    type: backend
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      annotations:
        openshift.io/generated-by: OpenShiftWebConsole
      creationTimestamp: null
      labels:
        app: postgres
        deploymentconfig: postgres
        type: backend
    spec:
      containers:
        - env:
            - name: PGDATA
              value: /var/lib/postgresql/data/sql
            - name: POSTGRES_HOST_AUTH_METHOD
              value: trust
            - name: POSTGRESQL_USER
              value: sentry
            - name: POSTGRESQL_PASSWORD
              value: sentry
            - name: POSTGRESQL_DATABASE
              value: sentry
          image: BLANK
          imagePullPolicy: Always
          name: postgres
          ports:
            - containerPort: 5432
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: volume-uirge
              subPath: sql
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext:
        runAsUser: 2000020900
      terminationGracePeriodSeconds: 30
      volumes:
        - name: volume-uirge
          persistentVolumeClaim:
            claimName: postgressql
  test: false
  triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
          - postgres
        from:
          kind: ImageStreamTag
          name: 'postgres:latest'
          namespace: catcloud
        lastTriggeredImage: BLANK
      type: ImageChange
status:
  availableReplicas: 1
  conditions:
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: Deployment config has minimum availability.
      status: 'True'
      type: Available
    - lastTransitionTime: BLANK
      lastUpdateTime: BLANK
      message: replication controller "postgres-9" successfully rolled out
      reason: NewReplicationControllerAvailable
      status: 'True'
      type: Progressing
  details:
    causes:
      - type: ConfigChange
    message: config change
  latestVersion: 9
  observedGeneration: 10
  readyReplicas: 1
  replicas: 1
  unavailableReplicas: 0
  updatedReplicas: 1
apiVersion: v1
kind: Service
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftWebConsole
  creationTimestamp: BLANK
  labels:
    app: postgres
    type: backend
  name: postgres
  namespace: catcloud
  resourceVersion: '506548841'
  selfLink: /api/v1/namespaces/catcloud/services/postgres
  uid: BLANK
spec:
  clusterIP: BLANK
  ports:
    - name: 5432-tcp
      port: 5432
      protocol: TCP
      targetPort: 5432
  selector:
    deploymentconfig: postgres
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
默认情况下,POD(即使在同一名称空间中)也不能直接彼此交谈。您需要创建一个
服务
,以允许一个pod接收来自另一个pod的连接。通常,一个pod通过另一个pod的服务连接到另一个pod,如下所示:

连接信息看起来像
(例如
elasticsearch主机:9200
),而不是
localhost:port

您可以阅读了解有关服务的更多信息

注意:
localhost:port
只适用于运行在同一个pod内的容器彼此连接,就像上面我的插图中nginx如何连接到graviree管理api和graviree管理ui一样。

默认情况下,pod(即使在同一名称空间中)也不能直接相互通信。您需要创建一个
服务
,以允许一个pod接收来自另一个pod的连接。通常,一个pod通过另一个pod的服务连接到另一个pod,如下所示:

连接信息看起来像
(例如
elasticsearch主机:9200
),而不是
localhost:port

您可以阅读了解有关服务的更多信息


注意:
localhost:port
仅适用于运行在同一pod内的容器,以便彼此连接,就像我上面的插图中nginx如何连接到重力管理api和重力管理ui一样。

对于pod之间的通信
localhost
127.0.0.1
不起作用

使用以下命令获取任何吊舱的IP

kubectl describe podname
使用另一个pod中的IP与上面的pod通信


由于如果重新创建Pod,Pod IP会发生变化,因此理想情况下,您应该专门使用
clusterIP
类型用于集群内Pod之间的通信。

用于Pod之间的通信
localhost
127.0.0.1
不起作用

使用以下命令获取任何吊舱的IP

kubectl describe podname
使用另一个pod中的IP与上面的pod通信


由于如果重新创建Pod,Pod IP会发生变化,因此理想情况下,您应该专门使用
clusterIP
类型在集群内的Pod之间进行通信。

对我来说,您似乎没有正确配置sentry,这意味着您没有向sentry Pod提供连接到PostgreSQL Pod和redis Pod的凭据

env:
    - name: SENTRY_SECRET_KEY
      valueFrom:
        secretKeyRef:
          name: sentry-sentry
          key: sentry-secret
    - name: SENTRY_DB_USER
      value: "sentry"
    - name: SENTRY_DB_NAME
      value: "sentry"
    - name: SENTRY_DB_PASSWORD
      valueFrom:
        secretKeyRef:
          name: sentry-postgresql
          key: postgres-password
    - name: SENTRY_POSTGRES_HOST
      value: sentry-postgresql
    - name: SENTRY_POSTGRES_PORT
      value: "5432"
    - name: SENTRY_REDIS_PASSWORD
      valueFrom:
        secretKeyRef:
          name: sentry-redis
          key: redis-password
    - name: SENTRY_REDIS_HOST
      value: sentry-redis
    - name: SENTRY_REDIS_PORT
      value: "6379"
    - name: SENTRY_EMAIL_HOST
      value: "smtp"
    - name: SENTRY_EMAIL_PORT
      value: "25"
    - name: SENTRY_EMAIL_USER
      value: ""
    - name: SENTRY_EMAIL_PASSWORD
      valueFrom:
        secretKeyRef:
          name: sentry-sentry
          key: smtp-password
    - name: SENTRY_EMAIL_USE_TLS
      value: "false"
    - name: SENTRY_SERVER_EMAIL
      value: "sentry@sentry.local"
要了解更多信息,你可以参考他们配置哨兵的地方


对我来说,您似乎没有正确配置sentry,这意味着您没有向sentry pod提供连接PostgreSQL pod和redis pod的凭据

env:
    - name: SENTRY_SECRET_KEY
      valueFrom:
        secretKeyRef:
          name: sentry-sentry
          key: sentry-secret
    - name: SENTRY_DB_USER
      value: "sentry"
    - name: SENTRY_DB_NAME
      value: "sentry"
    - name: SENTRY_DB_PASSWORD
      valueFrom:
        secretKeyRef:
          name: sentry-postgresql
          key: postgres-password
    - name: SENTRY_POSTGRES_HOST
      value: sentry-postgresql
    - name: SENTRY_POSTGRES_PORT
      value: "5432"
    - name: SENTRY_REDIS_PASSWORD
      valueFrom:
        secretKeyRef:
          name: sentry-redis
          key: redis-password
    - name: SENTRY_REDIS_HOST
      value: sentry-redis
    - name: SENTRY_REDIS_PORT
      value: "6379"
    - name: SENTRY_EMAIL_HOST
      value: "smtp"
    - name: SENTRY_EMAIL_PORT
      value: "25"
    - name: SENTRY_EMAIL_USER
      value: ""
    - name: SENTRY_EMAIL_PASSWORD
      valueFrom:
        secretKeyRef:
          name: sentry-sentry
          key: smtp-password
    - name: SENTRY_EMAIL_USE_TLS
      value: "false"
    - name: SENTRY_SERVER_EMAIL
      value: "sentry@sentry.local"
要了解更多信息,你可以参考他们配置哨兵的地方


请添加部署配置和服务yaml请添加部署配置和服务yaml