查看pod配置清单
参考: (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/)
[[email protected] ~]# kubectl explain pods.metadata.[.........]
[[email protected] ~]# kubectl explain pods.spec.[........]
开放端口+ip地址访问:此处的一旦绑定,只能指定的ip或者端口访问
[[email protected] ~]# kubectl explain pods.spec.containers.ports
containerPort : 容器开放端口
hostIP: 绑定宿主机ip
hostPort:绑定宿主机端口
name: 必须是IANA_SVC_NAME,并且是pod唯一
protocol :协议端口 必须是UDP TCP SCTP类型,默认TCP
语法:
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: nginx-1
ports:
- protocol: TCP
conainerPort: 80
name: http
hostPort: 8888
[[email protected] ~]# cat nginx_pods.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-demo1
namespace: prod
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: nginx-1
ports:
- protocol: TCP
containerPort: 80
hostPort: 8888
name: http-nginx
[[email protected] ~]# kubectl apply -f nginx_pods.yaml
[[email protected] ~]# kubectl get pods/pod-demo1 -n prod -o wide
切换到29服务器查看
访问测试
绑定宿主机hostIP
ports:
- protocol: TCP
containerPort: 80
hostPort: 8888
name: http-nginx
hostIP: 192.168.1.101
外部客户端访问 内部ip地址的方式
service->Nodeport
[[email protected] ~]# kubectl create service clusterip nginx-dep --tcp=80:80
根据开放节点数量,直接访问(所有node节点都可以访问)
hostPort 上述实例 只能指定节点的ip+端口可以访问
hostNetwork 只能访问指定宿主机ip+端口访问
spec:
containers:
- image: nginx
imagePullPolicy: IfNotPresent
name: nginx-1
hostNetwork: true
原文地址:https://blog.51cto.com/9025736/2397839
时间: 2024-11-10 14:06:22