【问题标题】:How to handle multiple ports under the same container in kubernetes yaml filekubernetes yaml文件中如何处理同一个容器下的多个端口
【发布时间】:2019-11-08 13:23:22
【问题描述】:

sn-p 在 docker-compose.yml

graphite:
  image: sitespeedio/graphite:1.1.5-3
  ports:
   - "2003:2003"
   - "8080:80"
  restart: always

kube.yml 中的当前 sn-p 需要更改

spec:
  containers:
  - name: graphite
    image: sitespeedio/graphite:1.1.5-3
    restartPolicy: Always
    ports:
    - containerPort: 2003

这里,如何将第二个提到的- "8080:80" 端口写入kubernetes yaml 文件中?

【问题讨论】:

  • 您好,如果您想拥有更多端口,您需要指定名称
  • kubectl explain pods.spec.containers.ports 将提供更多信息
  • 我试过这样ports: - name: graphite_one containerPort: 8080 hostPort: 80 - name: graphite_two containerPort: 2003 hostPort: 2003
  • @SureshVishnoi 以上真的很有帮助
  • @SureshVishnoi 我试图管理和修复它;有一个清晰的想法:)

标签: kubernetes


【解决方案1】:
spec:
  containers:
  - name: graphite
    image: sitespeedio/graphite:1.1.5-3
    restartPolicy: Always
    ports:
    - containerPort: 2003
      name: graphite_two 
    - containerPort: 8080
      name: graphite_one 

将解决您的问题。

kubectl explain pods.spec.containers.ports 提供有关键和值的详细信息

【讨论】:

  • 太棒了!有帮助
猜你喜欢
  • 2020-01-30
  • 2020-07-01
  • 1970-01-01
  • 2018-05-22
  • 1970-01-01
  • 2011-08-22
  • 2022-12-09
  • 1970-01-01
  • 2015-08-13
相关资源
最近更新 更多