Reputation: 483
I have backend service description in skaffold.yaml similiar this:
...
deploy:
helm:
releases:
- name: 'myapp-backend'
chartPath: myapp-chart-backend
values:
APP_IMAGE: ...
namespace: myapp-ns
recreatePods: true
...
After cluster is up I have list pods and kubectl get pods
return
...
myapp-backend-7dbf4b6fb8-kw7zv
myapp-backend-redis-646f454bcb-7thrc
...
I need full name of pod (myapp-backend-7dbf4b6fb8-kw7zv
) to use it in kubectl cp
command, which requires full name.
But this command I run in my bash script, so I need to get full name myapp-backend-7dbf4b6fb8-kw7zv
by name myapp-backend
.
Upvotes: 0
Views: 3147
Reputation: 42541
Assuming you know the name in the deployment ('myapp-backend' in this case), you can:
kubectl get pods --selector=app=myapp-backend -o jsonpath='{.items[*].metadata.name}'
Update
Since I obviously don't have an access to your environment, I've rather provided a a general path for solution, you can fiddle with this command but the idea probably will remain the same:
kubectl get pods --selector=...
(Its possible that you should add more selectors in __your__environment)kubectl get pods --selector=app=<myapp-backend> -o json
. You'll get a properly formatted json that you can inspect and see what part of it you actually want to get.{.items[0].metadata.name}
will also workUpvotes: 2