仅使用一个端口时需要多个端口名称
Multiple port names required when only using one port
我有一个端口指定如下。
我的应用-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 总结:
steps:
- name: gcr.io/cloud-builders/gcloud
- name: gcr.io/cloud-builders/docker
- name: gcr.io/cloud-builders/gke-deploy
出于某种原因,当 port1 甚至不存在时,我在请求 port1 上的名称参数时遇到错误。见下文。
输出:
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 版本:1.15.9-gke.24
有人知道我错过了什么吗?
似乎是 yaml 对齐问题。确保端口数组在 "ports"
下缩进
尝试:
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
重新创建 yaml 成功了:
kubectl delete -f service.yaml
kubectl apply -f service.yaml
我有一个端口指定如下。
我的应用-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 总结:
steps:
- name: gcr.io/cloud-builders/gcloud
- name: gcr.io/cloud-builders/docker
- name: gcr.io/cloud-builders/gke-deploy
出于某种原因,当 port1 甚至不存在时,我在请求 port1 上的名称参数时遇到错误。见下文。
输出:
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 版本:1.15.9-gke.24
有人知道我错过了什么吗?
似乎是 yaml 对齐问题。确保端口数组在 "ports"
下缩进尝试:
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
重新创建 yaml 成功了:
kubectl delete -f service.yaml
kubectl apply -f service.yaml