Kubernetes(10):Pod端口设置

端口设置

ports支持的子选项

[root@master ~]# kubectl explain pod.spec.containers.ports
KIND:     Pod
VERSION:  v1
RESOURCE: ports <[]Object>
FIELDS:
   containerPort	<integer> -required-
     Number of port to expose on the pod's IP address. This must be a valid port
     number, 0 < x < 65536.
     #容器要监听的端口号(0<x<65536)
   hostIP	<string>
     What host IP to bind the external port to.
     #要将外部端口绑定到主机IP(一般省略)
   hostPort	<integer>
     Number of port to expose on the host. If specified, this must be a valid
     port number, 0 < x < 65536. If HostNetwork is specified, this must match
     ContainerPort. Most containers do not need this.
     #容器要在主机上公开的端口,如果设置,主机上只能运行容器的一个副本(一般省略)
   name	<string>
     If specified, this must be an IANA_SVC_NAME and unique within the pod. Each
     named port in a pod must have a unique name. Name for the port that can be
     referred to by services.
	 #端口名称,如果要指定,必须保证name在pod中式唯一的
   protocol	<string>
     Protocol for port. Must be UDP, TCP, or SCTP. Defaults to "TCP".
     #端口协议。必须式UDP、TCP或者SCTP。默认是TCP

[root@master ~]# 

创建pod-ports.yaml文件,内容如下

apiVersion: v1
kind: Pod
metadata:
  name: pod-ports
  namespace: dev
spec:
  containers:
    - name: nginx
      image: nginx:1.17.1
      ports:
        - name: nginx-port
          containerPort: 80
          protocol: TCP

创建pod

kubectl create -f pod-ports.yaml

查看pod的详细信息

kubectl get pods pod-ports -n dev -o yaml

在这里插入图片描述

访问容器中的程序需要使用的是podIp:containerPort

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值