Search code examples
kubernetesbazel

Is it possible to deploy Kubernetes application through Bazel?


I want to automate the deployment procedure of my kubernetes pod manifest file through Bazel. I have gone through k8s_object in Bazel which takes information of the k8s context, cluster and kubeconfig file , not sure how i can make use of it to deploy my application in k8s tenant.


Solution

  • You need to use the k8s_object to interact with Kubernetes cluster.

    You can create a Deployment that will deploy your application to the cluster:

    Here is an example nginx-deployment.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
      labels:
        app: nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
    

    You have to use that yaml file as a template in the bazel k8s_object, so it would look like this: k8s_object(name = "nginx", kind = "create", template = "nginx-deployment.yaml")