From 864813deb9f580a87ac456745fd25342b34086e1 Mon Sep 17 00:00:00 2001 From: Tim Oesterreich Date: Tue, 1 Mar 2022 14:05:05 +0100 Subject: [PATCH 1/2] add possibility to specify node_port --- components/generators/kubernetes/__init__.py | 9 +++++++-- inventory/classes/components/echo-server.yml | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/components/generators/kubernetes/__init__.py b/components/generators/kubernetes/__init__.py index 871f66d0..7bdac421 100644 --- a/components/generators/kubernetes/__init__.py +++ b/components/generators/kubernetes/__init__.py @@ -311,12 +311,17 @@ 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 += [{ + ports = { 'name': port_name, 'port': port_spec.service_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): diff --git a/inventory/classes/components/echo-server.yml b/inventory/classes/components/echo-server.yml index deaa4b1a..b12d061f 100644 --- a/inventory/classes/components/echo-server.yml +++ b/inventory/classes/components/echo-server.yml @@ -30,12 +30,14 @@ parameters: # Networking service: - type: LoadBalancer + type: NodePort ports: http: container_port: 8080 + node_port: 30001 internal: container_port: 8081 + node_port: 30002 # One or many network policies network_policies: From 8eda2c8bebbb26a7151b61717eb5aae8fa6c4aa6 Mon Sep 17 00:00:00 2001 From: "danny.heinrich" Date: Tue, 1 Mar 2022 15:40:52 +0100 Subject: [PATCH 2/2] specify container_port as default for service_port --- .../echo-server/manifests/echo-server-service.yml | 12 +++++++++++- compiled/tutorial/manifests/echo-server-service.yml | 11 +++++++++-- components/generators/kubernetes/__init__.py | 4 ++-- inventory/classes/components/echo-server.yml | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/compiled/echo-server/manifests/echo-server-service.yml b/compiled/echo-server/manifests/echo-server-service.yml index 83082a19..23aabf49 100644 --- a/compiled/echo-server/manifests/echo-server-service.yml +++ b/compiled/echo-server/manifests/echo-server-service.yml @@ -7,6 +7,16 @@ 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 @@ -14,4 +24,4 @@ spec: selector: name: echo-server sessionAffinity: None - type: LoadBalancer + type: NodePort diff --git a/compiled/tutorial/manifests/echo-server-service.yml b/compiled/tutorial/manifests/echo-server-service.yml index 182acd1a..8b92ab05 100644 --- a/compiled/tutorial/manifests/echo-server-service.yml +++ b/compiled/tutorial/manifests/echo-server-service.yml @@ -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 diff --git a/components/generators/kubernetes/__init__.py b/components/generators/kubernetes/__init__.py index 7bdac421..d0946652 100644 --- a/components/generators/kubernetes/__init__.py +++ b/components/generators/kubernetes/__init__.py @@ -310,10 +310,10 @@ def body(self): for port_name in sorted(exposed_ports): port_spec = exposed_ports[port_name] - if 'service_port' in port_spec: + 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') } diff --git a/inventory/classes/components/echo-server.yml b/inventory/classes/components/echo-server.yml index b12d061f..3e21be20 100644 --- a/inventory/classes/components/echo-server.yml +++ b/inventory/classes/components/echo-server.yml @@ -34,6 +34,7 @@ parameters: ports: http: container_port: 8080 + service_port: 9999 node_port: 30001 internal: container_port: 8081