How to setup k8s_default in Bazel for my project?

10/15/2019

I have a project with some files like this:

# To use Bazel
/home/slackware/tgkj/WORKSPACE

# To use Bazel and https://github.com/bazelbuild/rules_k8s
/home/slackware/tgkj/app/BUILD

# The app to be ran on the kubernetes cluster.
/home/slackware/tgkj/app/main.py

# To deploy EC2 instances using terraform
/home/slackware/tgkj/infra/terraform.tf

# To tell Packer how to build the AMIs (provision using ansible) to deploy to EC2
/home/slackware/tgkj/infra/example.jsonnet

# To tell Ansible how to provision the AMI
# (Install kubernetes master packages for the master AMI
#  and node packages for the node AMI)
/home/slackware/tgkj/infra/playbook_template.jsonnet

I am able to create my EC2 instances using terraform, and build+provision my AMIs using Packer+Ansible.

Now, I would like to deploy my main.py program on the kubernetes cluster.

Note: Indeed, I am missing some kubernetes deployment.yaml file. It is in my filesystem, but I don't understand it yet to list it here in full confidence, and it is not the focus of this question.

I found https://github.com/bazelbuild/rules_k8s and I would like to use it to specify a build target for deploying an image. I am able to use the py3_image() (from https://github.com/bazelbuild/rules_docker) directive to create a python3 image target.

The confusion is in bazelbuild/rules_k8s . If you look at https://github.com/bazelbuild/rules_k8s#aliasing-eg-k8s_deploy or https://github.com/bazelbuild/rules_k8s#k8s_defaults , there is a mention of specifying a "cluster" .


I was wondering, which kubectl config current-context context would such a build target use? The current one? Can I put a file kubeconfig in /home/slackware/tgkj/, the root of the project, and have kubectl automatically use that config file when I use kubectl from inside the project directory? Do you think I should do things differently?

-- Slackware
bazel
kubeconfig
kubectl
kubernetes
terraform

0 Answers