0

I have created a service-per-pod for statefulset, and it's working for a single port (80/tcp). However, I need to use it for multiple ports (e.g., 80/tcp, 30000/udp, etc.).

How can I extend this to multiple ports in service-per-pod Metacontroller?

sync-service-per-pod.jsonnet - image

lorena
  • 386
  • 1
  • 2
  • 15
  • 1
    Did you try something like https://github.com/metacontroller/metacontroller/blob/master/examples/service-per-pod/my-statefulset.yaml#L21 in your annotation? – Gari Singh Oct 11 '21 at 10:05
  • No, But needed jsonnet based example for multiple ports in metacontroller https://i.stack.imgur.com/OvNXX.png – Vignesh Palanisamy Oct 12 '21 at 07:54

1 Answers1

0

The service-per-pod sample actually shows you how to do this in manifest/sync-service-per-pod.jsonnet.

The service-per-pod-ports annotation allows you to specify a comma-delimited set of ports which will be exposed by the generated Service:

service-per-pod-ports: "80:80,8080:8080"

Then in sync-service-per-pod.jsonnet:

Get the ports

local ports = statefulset.metadata.annotations["service-per-pod-ports"]

And then loop through them creating multiple ports in the Service spec:

   ports: [
      {
        local parts = std.split(portnums, ":"),
        name: "port-" + std.parseInt(parts[0]),
        port: std.parseInt(parts[0]),
        targetPort: std.parseInt(parts[1]),
      }
      for portnums in std.split(ports, ",")
    ]

Note the for portnums in std.split(ports, ",") iterates over the ports set above.

Looks like you are trying to do something a bit more dynamic, so you could so something like:

for index in std.range(1,N) 

where N is is the maximum value of index.

Gari Singh
  • 11,418
  • 2
  • 18
  • 41