Bazel rules_k8s - How to Apply External Configuration Files? (From URL)

2/12/2020

I am trying to fully automate the deployment to my Kubernetes Cluster with Bazel and rules_k8s. But I don't know how to apply external configurations to my cluster. Usually I would run a command like

kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v0.12.0/cert-manager.yaml

But I want this to happen automatically when I run my

k8s_objects(
    name = "kubernetes_deployment",
    objects = [
        "//kubernetes:nginx",
        "//services/gateway:k8s",
        "//services/ideas:k8s",
        # ...
    ]
)

rule to deploy everything to Kubernetes.

-- Florian Ludewig
bazel
google-kubernetes-engine
kubectl
kubernetes

1 Answer

3/21/2020

try this in your BUILD file, I'm not sure its the best way as it will be re-ran on every build. It would be nice if we could use an http_file here instead of a genrule.

genrule(
        name = "extyaml",
        srcs = [],
        outs = ["certman-k8s.yaml"],
        cmd = "curl -L https://github.com/jetstack/cert-manager/releases/download/v0.12.0/cert-manager.yaml > $@",
    )


    k8s_object(
        name = "certman",
        cluster = "minikube",
        template = ":certman-k8s.yaml",
    )
-- mancini0
Source: StackOverflow