Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

google cloud platform - How to expose multiple port using a load balancer services in Kubernetes

I have created a cluster using the google cloud platform (container engine) and deployed a pod using the following YAML file:

apiVersion: extensions/v1beta1
kind: Deployment
metadata: 
  name: deployment-name
spec:
  replicas: 1
  template:
    metadata:
      name: pod-name
      labels: 
        app: app-label
    spec:
      containers: 
      - name: container-name
      image: gcr.io/project-id/image-name
      resources:
        requests:
          cpu: 1
      ports:
      - name: port80
        containerPort: 80
      - name: port443
        containerPort: 443
      - name: port6001
        containerPort: 6001

Then I want to create a service that enables the pod to listen on all these ports. I know that the following YAML file works to create a service that listens on one port:

apiVersion: v1
kind: Service
metadata: 
  name: service-name
spec:    
  ports:
  - port: 80
    targetPort: 80
  selector: 
    app: app-label
  type: LoadBalancer

However when I want the pod to listen on multiple ports like this, it doesn't work:

apiVersion: v1
kind: Service
metadata: 
  name: service-name
spec:    
  ports:
  - port: 80
    targetPort: 80
  - port: 443
    targetPort: 443
  - port: 6001
    targetPort: 6001
  selector: 
    app: app-label
  type: LoadBalancer

How can I make my pod listen to multiple ports?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...