https://pulumi.com logo
#general
Title
# general
f

freezing-umbrella-80278

03/11/2022, 5:56 PM
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

freezing-umbrella-80278

03/11/2022, 7:45 PM
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

billowy-army-68599

03/11/2022, 7:57 PM
i ran the docker image and it piped out some kubernetes yaml, so you culd easily convert that to pulumi directly
f

freezing-umbrella-80278

03/11/2022, 8:00 PM
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

billowy-army-68599

03/11/2022, 8:45 PM
that totally works too, I just like to keep my code as pulumi'd as possible
f

freezing-umbrella-80278

03/11/2022, 8:46 PM
What about the uninstall?
b

billowy-army-68599

03/11/2022, 8:46 PM
f

freezing-umbrella-80278

03/11/2022, 8:46 PM
Ahh that's neat
b

billowy-army-68599

03/11/2022, 8:47 PM
you can probably create a component that takes the token as an argument
f

freezing-umbrella-80278

03/11/2022, 8:47 PM
I hope that's not a real token?
b

billowy-army-68599

03/11/2022, 8:48 PM
it's the base64 of
REDACTED
f

freezing-umbrella-80278

03/11/2022, 8:48 PM
ahh 😄
kube2pulumi didn't know about that thanks
b

billowy-army-68599

03/11/2022, 8:49 PM
there's a cli tool as well
f

freezing-umbrella-80278

03/11/2022, 8:51 PM
Can you pipe things through the CLI tool?
b

billowy-army-68599

03/11/2022, 9:00 PM
yup
5 Views