https://pulumi.com logo
#python
Title
# python
c

clean-engineer-75963

12/06/2019, 5:17 PM
Anyone have tips for getting a reference to a Kubernetes Pod created by a deployment? The Pod's name isn't known, so core.v1.Pod.get doesn't seem like it will work.
Neither the Deployment nor its ReplicaSet seem to contain refernences to the names.
g

gorgeous-egg-16927

12/06/2019, 5:30 PM
Can you give some more details about what you’re trying to accomplish?
c

clean-engineer-75963

12/06/2019, 5:31 PM
I have a fiddly deploy step where I need to create a Deployment, then port-forward into one of the Pods it creates to finish configuring the software.
g

gorgeous-egg-16927

12/06/2019, 5:32 PM
What are you using to do the port-forwarding? kubectl?
c

clean-engineer-75963

12/06/2019, 5:33 PM
Yes, since the Python kubernetes client doesn't support it yet.
g

gorgeous-egg-16927

12/06/2019, 5:33 PM
Ok, then I’d suggest using the selector to find the Pod(s) rather than using the name directly
c

clean-engineer-75963

12/06/2019, 5:34 PM
kubectl port-forward
doesn't support
-l
.
g

gorgeous-egg-16927

12/06/2019, 5:35 PM
You can do something like
Copy code
kubectl get pods --selector=app=cassandra
to list all matching pods, and could further filter that down as needed
c

clean-engineer-75963

12/06/2019, 5:36 PM
Yes, definitely an option. I was wondering if there was a Pulumi-native way to do it.
g

gorgeous-egg-16927

12/06/2019, 5:38 PM
Well, if you figure out the correct kubectl incantation, you should be able to shell out to it from within a pulumi program and then use that output
Or use a k8s client for python
That scenario is currently a bit outside of our main workflow, but feel free to open an issue on https://github.com/pulumi/pulumi-kubernetes/issues if you want to provide more details on your use case.
kubectl get pods --selector=tier=frontend -o jsonpath='{.items[0].metadata.name}'
will get you just the pod name