kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.83k stars 913 forks source link

`kubectl logs -f` Is there a reason `-f` still errors when a pod is in state `ContainerCreating`? Can it wait? #1612

Closed carterjfulcher closed 2 months ago

carterjfulcher commented 3 months ago

As Kubernetes developers, we often find ourselves repeatedly hitting the UpArrow + Enter combo in the terminal while waiting for a pod to start, to ensure we don’t miss any log output.

I am recommending a change which enhances the -f flag to wait until the pod is fully initialized during ContainerCreating status instead of erroring, making the development process smoother and more efficient.

The error in particular I'm referring to is the following, when kubectl logs -f [POD_ID] is invoked on a pod with status ContainerCreating:

Error from server (BadRequest): container "pod-name" in pod "pod-id" is waiting to start: ContainerCreating

I am happy to submit a PR for this change, if approved.

k8s-ci-robot commented 3 months ago

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
brianpursley commented 3 months ago

Does something like this work for what you need?

kubectl wait --for=condition=Ready pod/foo && kubectl logs -f pod/foo

You could even turn this into a simple plugin by putting it into a file called kubectl-waitlogs somewhere in your path:

#!/bin/sh
kubectl wait --for=condition=Ready pod/$1 && kubectl logs -f pod/$1

And then chmod +x kubectl-waitlogs

and now you can:

kubectl waitlogs foo
ardaguclu commented 2 months ago

https://github.com/kubernetes/kubernetes/pull/125868 brings about new for condition just for creation.

$ kubectl wait --for=create pod/test-1
$ kubectl logs -f pod/test-1

I'd prefer closing this issue.

mpuckett159 commented 2 months ago

/close

This has been solved by a few options.

k8s-ci-robot commented 2 months ago

@mpuckett159: Closing this issue.

In response to [this](https://github.com/kubernetes/kubectl/issues/1612#issuecomment-2233740157): >/close > >This has been solved by a few options. Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.