Zaman
Zaman

Reputation: 873

Expose/rexpose new port on running/exist pod podman

Based on podman-add-ports-to-expose-to-running-pod as quote From Dominic P:

once the pod is created these attributes are assigned to the “infra” container and cannot be changed. For example, if you create a pod and then later decide you want to add a container that binds new ports, Podman will not be able to do this. You would need to recreate the pod with the additional port bindings before adding the new container.

I know it's not supported to add new port for running pod

So, what is your suggestion to recreate (backup exist containers on pod) then create new pod and add the new port and restore the containers?

Upvotes: 0

Views: 954

Answers (1)

larsks
larsks

Reputation: 311721

You could generate a Kubernetes pod manifest from your running pod using podman generate kube <podname>, edit the resulting file, and then re-create the pod with podman kube play <manifest>,yaml.

For example:

I create a pod and spin up a webserver...

podman pod create example-pod
podman run -d --name web --pod example-pod alpinelinux/darkhttpd

...only to realize that I forgot to publish port 8080 to the host. So I save the configuration and delete the pod:

podman generate kube example-pod > example-pod.yaml
podman pod rm -f example-pod

Edit the manifest to add the port configuration:

...
spec:
  containers:
  - image: docker.io/alpinelinux/darkhttpd:latest
    name: web
    ports:
      - containerPort: 8080
        hostPort: 8080
...

And then re-create the pod:

podman kube play example-pod.yaml

Upvotes: 2

Related Questions