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 x.x.x.x: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. 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. 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: {}
CodePudding user response:
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
CodePudding user response:
But I also want to use port 7777 from the outside