Is it possible to perform a `kubectl apply` with `...
# general
f
Is it possible to perform a
kubectl apply
with
pulumi
. I'm trying to install GitLab Agent on a Kubernetes cluster and the "recommended method of installation" is the following.
Copy code
docker run --pull=always --rm \
    <http://registry.gitlab.com/gitlab-org/cluster-integration/gitlab-agent/cli:stable|registry.gitlab.com/gitlab-org/cluster-integration/gitlab-agent/cli:stable> generate \
    --agent-token=REDACTED \
    --kas-address=<wss://kas.gitlab.com> \
    --agent-version stable \
    --namespace gitlab-kubernetes-agent | kubectl apply -f -
I was thinking I can probably run the Docker container via
pulumi
and get the output of the logs as a string. But then how can I apply that YAML with
kubectl
? I guess I could you the command package? https://www.pulumi.com/registry/packages/command/ But not very nice as it relies on my host's installation of
kubectl
and that it has access to the right cluster.
however, it looks like that docker image just generates some yaml which you pipe to
kubectl
on stdout, you can easily convert that to pulumi as well?
yep, I just confirmed. You can convert to Pulumi
f
Which bit did you confirm? That I could take the logs of the container and pipe it to a
local.Command
. Thanks for that example usage with
kubectl
.
b
i ran the docker image and it piped out some kubernetes yaml, so you culd easily convert that to pulumi directly
f
Could you paste what you have so far?
Copy code
const agentToken = config.requireSecret("gitlab-agent-token");

const gitlabAgentContainer = new docker.Container("gitlab-agent-container", {
  image:
    "<http://registry.gitlab.com/gitlab-org/cluster-integration/gitlab-agent/cli:stable|registry.gitlab.com/gitlab-org/cluster-integration/gitlab-agent/cli:stable>",
  rm: true,
  command: [
    "generate",
    `--agent-token=${agentToken}`,
    "--kas-address=<wss://kas.gitlab.com>",
    "--agent-version stable",
    "--namespace gitlab-kubernetes-agent",
  ],
});

module.exports = {
  logs: gitlabAgentContainer.containerLogs,
};
Copy code
const installGitlabAgent = new local.Command("install-gitlab-agent", {
  create: `echo ${gitlabAgentContainer.containerLogs} | kubectl apply -f -`,
  environment: {
    KUBECONFIG: provider.kubeconfig,
  },
});
🤷 ?
b
that totally works too, I just like to keep my code as pulumi'd as possible
f
What about the uninstall?
b
f
Ahh that's neat
b
you can probably create a component that takes the token as an argument
f
I hope that's not a real token?
b
it's the base64 of
REDACTED
f
ahh 😄
kube2pulumi didn't know about that thanks
b
there's a cli tool as well
f
Can you pipe things through the CLI tool?
b
yup