Kubernetes:打开Pod之间的不同服务连接

Kubernetes:打开Pod之间的不同服务连接

我已在 pod 存储上创建了两个服务连接(节点端口),用于通过端口 8885 和 8881 与 pod 应用进行通信。我了解到我需要在应用部署上使用与我指定的节点端口相同的名称的 matchselect。您能否向我展示一个实际示例,其中 pod 应用可以通过端口 8881 和 8885 访问 pod 存储?

我已经在应用程序容器(docker)中测试了 telnet demo-storage-manageport 8885 和 demo-storage-nodeport 8881,但是它不起作用。

服务连接:

apiVersion: v1
kind: Service
metadata:
  name: demo-storage-nodeport
  namespace: demo-customer
  labels:
    run: demo-storage
spec:
  type: NodePort
  ports:
  - port: 8881
    targetPort: 8881
    protocol: TCP
    name: tomcat-http
  selector:
    app: demo-app
---
apiVersion: v1
kind: Service
metadata:
  name: demo-storage-manageport
  namespace: demo-customer
  labels:
    run: demo-storage
spec:
  type: NodePort
  ports:
  - port: 8885
    targetPort: 8885
    protocol: TCP
    name: tomcat-http
  selector:
    app: demo-app

部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-app
  namespace: demo-customer
  labels:
    app: demo-app
    name: appserver
spec:
  selector:
    matchLabels:
      app: demo-app
      customer: demo-customer
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: demo-app
        customer: demo-customer
    spec:
      containers:
      - name: appserver
        image: xy.azurecr.io/client/demo-customer-app:latest
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: xy
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-storage
  namespace: demo-customer
  labels:
    app: demo-storage
    name: storageserver
spec:
  selector:
    matchLabels:
      app: demo-storage
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: demo-storage
    spec:
      volumes:
      - name: shared-config
        emptyDir: {}
      containers:
      - name: storageserver
        image: xy.azurecr.io/client/demo-customer-storage:latest
        ports:
        - containerPort: 8881
      imagePullSecrets:
      - name: xy

相关内容