Kubernetes logs with label selector does not work for some labeles

7/30/2019

When retrieving the logs using kubectl logs -l, it returns the logs for some of the labels, but it does not return anything for some other labels.

For example:

~/ $ kubectl logs -n test -lapp=testapp
~/ $ kubectl logs -n test -lapp.kubernetes.io/instance=test
2019-07-30 15:28:39.913  INFO 1 ---

The labels of the deployment:

~/ $ kubectl get deployments.apps -n test --show-labels 
NAME                    READY   UP-TO-DATE   AVAILABLE   AGE     LABELS
testapp                 1/1     1            1           55m     app.kubernetes.io/instance=test,app=testapp

Thanks

-- imriss
kubernetes
label
logging

1 Answer

7/30/2019

Make sure both the deployment and template labels are properly set.

    "template": {
      "metadata": {
        "labels": {
          "app": "testapp",
          "app.kubernetes.io/instance": "test"
        }
      },

You can use:

  • kubectl logs --selector app.kubernetes.io/instance=test
  • kubectl logs -l app.kubernetes.io/instance=test

Hope this helps

-- paulogrell
Source: StackOverflow