Kubernetes - services without selector

前端 未结 3 1738
忘掉有多难
忘掉有多难 2021-01-21 02:10

I\'m struggling with Kubernetes\' service without a selector. The cluster is installed on AWS with the kops. I have a deployment with 3 nginx pods exposing port 80:



        
相关标签:
3条回答
  • 2021-01-21 02:56

    As @iliefa mentioned in his comment above, the below part of the definition is treated as labels in this type of cases.

    ports:
        - port: 80
          name: http
    

    In your scenario, we need to either remove 'name: http' as mentioned by @iliefa or we need to add 'name: http' under 'ports:' in the service definition as you can spot below.

    apiVersion: v1
    kind: Service
    metadata:
      name: dummy-svc
      labels:
        app: nginx
    spec:
     ports:
        - protocol: TCP
          port: 80
          targetPort: 80
          name: http
    
    0 讨论(0)
  • 2021-01-21 02:58

    it works if you remove the "name" field from the endpoints configuration. it should look like this:

    apiVersion: v1
    kind: Endpoints
    metadata:
      name: dummy-svc 
    subsets: 
      - addresses:
        - ip: 172.17.0.4
        - ip: 172.17.0.5
        - ip: 172.17.0.6
        ports:
        - port: 80
    
    0 讨论(0)
  • 2021-01-21 03:04

    correct the service definition as below

    apiVersion: v1
    kind: Service
    metadata:
      name: dummy-svc
      labels:
        app: nginx
    spec:
      ports:
      - protocol: TCP
        port: 80
        targetPort: 80
      selector:
       app: nginx
    
    0 讨论(0)
提交回复
热议问题