rules_k8s
rules_k8s copied to clipboard
Why is k8s_default not allowing us to alias all the different k8s_object fields?
Hi bazelbuild/rules_k8s!
Thanks tons for this repository, I think it will be very useful for me.
I am looking to use Bazel alongside Kubernetes to run containers in remote instances (in my current case, it would be EC2 instances, but I don't want to necessarily stick to EC2 only).
My understanding of kubernetes is fairly low, and I have some confusion. I think this is the right place to ask.
My project looks like
/home/slackware/tgkj/WORKSPACE
/home/slackware/tgkj/app/BUILD
and other files..
In WORKSPACE, I use k8s_defaults to create a k8s_deploy:
k8s_defaults(
# This becomes the name of the @repository and the rule
# you will import in your BUILD files.
name = "k8s_deploy",
kind = "deployment",
# This is the name of the cluster as it appears in:
# kubectl config view --minify -o=jsonpath='{.contexts[0].context.cluster}'
cluster = "my-tgkj-cluster",
context = "my-tgkj-context",
namespace = "my-tgkj-namespace",
)
and I think that k8s_defaults is a way of creating a "k8s_object" rule type that has some fields already set. Like an alias. However, I find that only a subset of the "k8s_object" are available in the "k8s_default" rule.
I say this because I thought it would be nice to specify a /home/slackware/tgkj/kube.config for the kubeconfig of k8s_defaults so that all of the k8s_deploy rules that I would set up would use that configuration file.
I do not understand why we need to specify to kubectl what context to use. Why can't kubectl use a kube.config file at the root of the project instead? Also, why can't we specify to rules_k8s the kube.config file that kubectl should use?
I hope this makes sense.
Thank you!
kovkev
Hi @kovkev,
The k8s_object does have a kubeconfig argument that lets you specify the kubeconfig file. However, as you said, this is currently not possible via the k8s_defaults rule to conveniently set it for more than one k8s_object target.
If you would like this feature, feel free to send a PR adding the ability to specify a kubeconfig file to k8s_defaults and I'll be happy to review it.
Thank you for using rules_k8s.
Strangely enough, I see kubeconfig here: https://github.com/bazelbuild/rules_k8s/blob/5648b17d5f9b612cc47031a6fa961e6752fe50e8/examples/hellogrpc/BUILD#L32