Willy G
Willy G

Reputation: 1252

Multiple port names required when only using one port

I have one port specified as below.

my-app-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: my-app
  name: my-app-service
  namespace: default
spec:
  externalTrafficPolicy: Cluster
  ports:
    - port: 80
      name: my-port
      protocol: TCP
      targetPort: 8000
  selector:
    app: my-app
  sessionAffinity: None
  type: NodePort

cloudbuild.yaml summary:

steps:
  - name: gcr.io/cloud-builders/gcloud
  - name: gcr.io/cloud-builders/docker
  - name: gcr.io/cloud-builders/gke-deploy

For some reason I get an error asking for a name param on port1, when port1 doesn't even exist. See below.

output:

Step #3: Applying deployment.
Step #3: Getting access to cluster "my-cluster" in "my-zone".
Step #3: Configuration files to be used: [{kind: Deployment, name: my-app} {kind: HorizontalPodAutoscaler, name: my-app-hpa} {kind: Service, name: my-app-service}]
Step #3: Applying configuration files to cluster.
Step #3: Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
Step #3: The Service "my-app-service" is invalid: 
Step #3: * spec.ports[1].name: Required value

Kubernetes version: 1.15.9-gke.24

Anyone know what I'm missing?

Upvotes: 2

Views: 8473

Answers (2)

Willy G
Willy G

Reputation: 1252

Recreating the yaml worked:

kubectl delete -f service.yaml
kubectl apply -f service.yaml

Upvotes: 9

lance.johnsn
lance.johnsn

Reputation: 506

Looks like yaml alignment issue. Make sure the array of ports is indented under "ports"

Try:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: my-app
  name: my-app-service
  namespace: default
spec:
  externalTrafficPolicy: Cluster
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 8000
  selector:
    app: my-app
  sessionAffinity: None
  type: NodePort

Upvotes: 0

Related Questions