I am building an application which should execute tasks in a separate container/pods. this application would be running in a specific namespace the new pods must be created in the same namespace as well.
I understand we can similar via custom CRD and Operators, but I found it is overly complicated and we need Golang knowledge for the same.
Is there any way this could be achived without having to learn Operators and GoLang?
I am ok to use kubctl
or api
within my container and wanted to connect the host and to the same namespace.
Yes, this is certainly possible using a ServiceAccount
and then connecting to the API from within the Pod.
First, create a ServiceAccount
in your namespace using
kubectl create serviceaccount my-service-account
For your newly created ServiceAccount
, give it the permissions you want using Roles
and RoleBindings
. The subject would be something like this:
subjects:
- kind: ServiceAccount
name: my-service-account
namespace: my-namespace
Then, add the ServiceAccount
to the Pod from where you want to create other Pods from (see documentation). Credentials are automatically mounted inside the Pod using automountServiceAccountToken
.
Now from inside the Pod you can either use kubectl
or call the API using the credentials inside the Pod. There are libraries for a lot of programming languages to talk to Kubernetes, use those.