Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] specify node port for serviceType NodePort #119

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiled/echo-server/manifests/echo-server-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ metadata:
namespace: echo-server
spec:
ports:
- name: http
nodePort: 30001
port: 9999
protocol: TCP
targetPort: http
- name: internal
nodePort: 30002
port: 8081
protocol: TCP
targetPort: internal
- name: nginx
port: 80
protocol: TCP
targetPort: nginx
selector:
name: echo-server
sessionAffinity: None
type: LoadBalancer
type: NodePort
11 changes: 9 additions & 2 deletions compiled/tutorial/manifests/echo-server-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ metadata:
namespace: tutorial
spec:
ports:
- name: http
nodePort: 30001
protocol: TCP
targetPort: http
- name: internal
nodePort: 30002
protocol: TCP
targetPort: internal
- name: nginx
port: 80
protocol: TCP
targetPort: nginx
selector:
name: echo-server
sessionAffinity: None
type: LoadBalancer
type: NodePort
13 changes: 9 additions & 4 deletions components/generators/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,18 @@ def body(self):

for port_name in sorted(exposed_ports):
port_spec = exposed_ports[port_name]
if 'service_port' in port_spec:
self.root.spec.ports += [{
if 'service_port' in port_spec or 'container_port' in port_spec:
ports = {
'name': port_name,
'port': port_spec.service_port,
'port': port_spec.get('service_port', port_spec.container_port),
'targetPort': port_name,
'protocol': port_spec.get('protocol', 'TCP')
}]
}

if 'node_port' in port_spec and service_spec.type == 'NodePort':
ports['nodePort'] = port_spec.node_port

self.root.spec.ports += [ports]


class Ingress(k8s.Base):
Expand Down
5 changes: 4 additions & 1 deletion inventory/classes/components/echo-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ parameters:

# Networking
service:
type: LoadBalancer
type: NodePort
ports:
http:
container_port: 8080
service_port: 9999
node_port: 30001
internal:
container_port: 8081
node_port: 30002

# One or many network policies
network_policies:
Expand Down