kubectl: how to display pod logs without specyfing the pod name explicitly?
Rather than using POD/$POD_NAME, you can use Deployment/$DEPLOYMENT_NAME to fetch the logs of pods
kubectl logs deployment/$DEPLOY_NAME
# Return snapshot logs from container nginx-1 of a deployment named nginx kubectl logs deployment/nginx -c nginx-1
kubectl logs --help
will provide more info
add a label to the deployment and use the label selector to lookup the logs from the matching pod.
Refer the below instructions
master $ kubectl run webapp --image=nginx --port=80 --labels="app=web"kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.deployment.apps/webapp createdmaster $master $ kubectl get deployNAME READY UP-TO-DATE AVAILABLE AGEwebapp 1/1 1 1 2m27smaster $master $ kubectl get po -owideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESwebapp-647c6cd6f4-pxr4g 1/1 Running 0 20s 10.44.0.1 node01 <none> <none>master $master $ curl 10.44.0.1<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and support please refer to<a href="http://nginx.org/">nginx.org</a>.<br/>Commercial support is available at<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>master $master $ kubectl logs -l app=web10.32.0.1 - - [23/Jul/2019:10:07:39 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.47.0" "-"