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

Pod logs for all containers like --all-containers in kubectl #3446

Closed
z0mb1ek opened this issue Sep 5, 2021 · 4 comments
Closed

Pod logs for all containers like --all-containers in kubectl #3446

z0mb1ek opened this issue Sep 5, 2021 · 4 comments

Comments

@z0mb1ek
Copy link

z0mb1ek commented Sep 5, 2021

Hi. How can I get all logs for pod? For example pod with init container and main container.
May be I can get logs for list of containers in each, but I cannot find any methods to get all containers in pod

@manusa manusa added the question label Sep 6, 2021
@manusa
Copy link
Member

manusa commented Sep 6, 2021

Relates to #2712

@z0mb1ek
Copy link
Author

z0mb1ek commented Sep 7, 2021

I don't see where I can get containers names for .inContainer() call

@rohanKanojia
Copy link
Member

I checked and looks like inContainer works for both regular containers and initContainers. You can easily get a list of all container names and init container names like this:

    try (KubernetesClient client = new DefaultKubernetesClient()) {
      Pod createdPod = client.pods()
        .load(PodInitContainerGetLog.class.getResourceAsStream("/pod-init-demo.yml"))
        .get();

      List<String> containerNames = createdPod.getSpec().getContainers().stream()
        .map(Container::getName)
        .collect(Collectors.toList());

      List<String> initContainerNames = createdPod.getSpec().getInitContainers().stream()
        .map(Container::getName)
        .collect(Collectors.toList());

    }

@stale
Copy link

stale bot commented Dec 26, 2021

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Dec 26, 2021
@stale stale bot closed this as completed Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants