0

How do you deploy from within Kubernetes container - using CI/CD?

Senario:

  1. I am building within Kubernetes using Kaniko
  2. Now how to run kubectl within Kuberneters. And I do have the right serviceAccount for it. First problem is to have a container ready for executing kubectl.

Note: - /bin/cat

I found this, but it give errors:

apiVersion: v1
kind: Pod
metadata:
  name: kubectl-deploy
spec:
  containers:
  - name: kubectl
    image: bitnami/kubectl:latest
    imagePullPolicy: Always
    command:
    - /bin/cat
    tty: true

Errors:

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  78s                default-scheduler  Successfully assigned default/kubectl-deploy to master
  Normal   Pulled     76s                kubelet            Successfully pulled image "bitnami/kubectl:latest" in 874.059036ms
  Normal   Pulled     74s                kubelet            Successfully pulled image "bitnami/kubectl:latest" in 860.59161ms
  Normal   Pulled     60s                kubelet            Successfully pulled image "bitnami/kubectl:latest" in 859.31958ms
  Normal   Pulling    33s (x4 over 77s)  kubelet            Pulling image "bitnami/kubectl:latest"
  Normal   Created    32s (x4 over 76s)  kubelet            Created container kubectl
  Normal   Started    32s (x4 over 76s)  kubelet            Started container kubectl
  Normal   Pulled     32s                kubelet            Successfully pulled image "bitnami/kubectl:latest" in 849.398179ms
  Warning  BackOff    7s (x7 over 73s)   kubelet            Back-off restarting failed container
Chris G.
  • 23,930
  • 48
  • 177
  • 302
  • What kind of project are you going to deploy? – DreamBold Nov 28 '22 at 09:12
  • I am pushing containers to public dockerHub, so first off just public dockerHub. – Chris G. Nov 28 '22 at 14:00
  • 1
    https://github.com/dreambold/kubernetes/tree/master/pods Here's the sample pod yml and some commands for you to run to start – DreamBold Nov 28 '22 at 15:18
  • Sorry, but is this not "only" standard kubectl commands - note I am looking for running kubectl from within a container in kubernetres. Deploying from within a container. – Chris G. Nov 29 '22 at 07:46

1 Answers1

1

I found this, but it give errors

When you run a Pod in Kubernetes, by default, it expect it to be a long running service. But in your case, you run a one-off command that terminates immediately. To run one-off commands in Kubernetes, it is easiest to run them as Kubernetes Jobs.

First problem is to have a container ready for executing kubectl.

Since you are using Tekton, have a look at the "deploy task" from Tekton Hub, it is configured with an image that includes kubectl.

Jonas
  • 121,568
  • 97
  • 310
  • 388