Getting error while creating the NodePort service in EKS cluster

2/20/2021

I am trying to create Nodeport service in my EKS cluster however I am getting error as for: "network/minikube/orderers/services.yaml": map: map[name:endpoint] does not contain declared merge key: port. Can anybody help me to fix the issue.

My service.yaml file

apiVersion: v1
kind: Service
metadata:
  name: orderer0-service
  labels: {
    component: orderer0,
    type: orderer
  }
spec:
  type: NodePort
  ports:
    - name: endpoint
    - port: 7050
      targetPort: 7050
      nodePort: 30050
  selector:
    component: orderer0
    type: orderer
-- Abhijeet1234
kubectl
kubernetes

2 Answers

2/20/2021

ports: is representing list of ports, where by - you are separating the ports, (name, port, targetPort, nodePort) these four are combinedly representing one service port values, and you mistakenly included another list in (- port: 7050), your yaml should be like below,

  ports:
    - name: endpoint
      port: 7050
      targetPort: 7050
      nodePort: 30050

YAML:

apiVersion: v1
kind: Service
metadata:
  name: orderer0-service
  labels: {
    component: orderer0,
    type: orderer
  }
spec:
  type: NodePort
  ports:
    - name: endpoint
      port: 7050
      targetPort: 7050
      nodePort: 30050
  selector:
    component: orderer0
    type: orderer
-- Sahadat Hossain
Source: StackOverflow

2/20/2021

The yaml has a problem.You don't need the - infront of port.It should be like below

apiVersion: v1
kind: Service
metadata:
  name: orderer0-service
  labels: {
    component: orderer0,
    type: orderer
  }
spec:
  type: NodePort
  ports:
    - name: endpoint
      port: 7050
      targetPort: 7050
      nodePort: 30050
  selector:
    component: orderer0
    type: orderer
-- Arghya Sadhu
Source: StackOverflow