[英]connect to pod from outside (k8s)
I created a deployment file which runs some service.我创建了一个运行一些服务的部署文件。 The service uses port 7777. I want to access the same service from the outside by typing the address xxxx:7777.
该服务使用端口 7777。我想通过键入地址 xxxx:7777 从外部访问相同的服务。 I am attaching my deployment file which is currently working properly without service.
我正在附加我的部署文件,该文件目前在没有服务的情况下正常工作。 If I download the Ports part from the Deployment and apply to the service, nothing works.
如果我从 Deployment 下载 Ports 部分并应用到该服务,则没有任何效果。 I need to prepare a service file because I will soon connect more additional services that will each use the same IP address but on different ports.
我需要准备一个服务文件,因为我很快将连接更多额外的服务,每个服务都使用相同的 IP 地址,但在不同的端口上。 What is the best way to work in order to achieve my goal?
为了实现我的目标,最好的工作方式是什么?
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml
kompose.version: 1.7.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: xyz
name: xyz
spec:
replicas: 1
strategy: {}
selector:
matchLabels:
io.kompose.service: xyz
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: xyz
spec:
nodeSelector:
node: w1
imagePullSecrets:
- name: registry-secret1
volumes:
- name: zzz
hostPath:
path: z/z/z
type: DirectoryOrCreate
- name: yyy
hostPath:
path: y/y/y
type: FileOrCreate
- name: xxx
hostPath:
path: x/x/x
type: FileOrCreate
containers:
- env:
- name: x
value: "x"
- name: y
value: "y"
name: quic-image
image: "xxxyyyzzz"
name: x-y-z
volumeMounts:
- mountPath: x/x/x
name: xxx
- mountPath: y/y/y
name: yyy
- mountPath: z/z/z
name: zzz
ports:
- containerPort: 7777
hostPort: 7777
protocol: UDP
- containerPort: 7777
hostPort: 7777
protocol: TCP
resources: {}
restartPolicy: Always
status: {}
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml
kompose.version: 1.7.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: xyz
name: xyz
spec:
clusterIP: None
ports:
- protocol: TCP
name: tcp
port: 7777
- protocol: UDP
name: udp
port: 7777
# targetPort: 7777
selector:
io.kompose.service: xyz
status:
loadBalancer: {}
Update the service type as nodeport as below将服务类型更新为节点端口,如下所示
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml
kompose.version: 1.7.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: xyz
name: xyz
spec:
type: NodePort
ports:
- protocol: TCP
name: tcp
port: 7777
nodePort: 30077
- protocol: UDP
name: udp
port: 7777
selector:
io.kompose.service: xyz
You can then access the service at HOSTNAME:30077然后您可以在 HOSTNAME:30077 访问该服务
But I also want to use port 7777 from the outside但我也想从外部使用端口 7777
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.