Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make kubectl work in gitlab ci

I am searching for a way to use kubectl in gitlab.

So far I have the following script:

deploy_to_dev:
  stage: deploy
  image: docker:dind
  environment:
    name: dev
  script:
    - mkdir -p $HOME/.kube
    - echo $KUBE_CONFIG | base64 -d > $HOME/.kube/config
    - kubectl config view
  only:
    - develop

But it says that gitlab does not know kubectl. So can you point me in the right direction.

like image 754
Tim Schwalbe Avatar asked Feb 23 '18 17:02

Tim Schwalbe


People also ask

How does Kubernetes cluster connect to GitLab CI?

You can connect your Kubernetes cluster with GitLab to deploy, manage, and monitor your cloud-native solutions. To connect a Kubernetes cluster to GitLab, you must first install an agent in your cluster. The agent runs in the cluster, and you can use it to: Communicate with a cluster, which is behind a firewall or NAT.

Is Kubernetes used for CI CD?

This Kubernetes-native architecture allows your CI/CD pipeline to be portable and function across multiple cloud providers and locations. The declarative nature of Tekton and Kubernetes allows you to standardize, collaborate, and share your workflows across teams.


Video Answer


1 Answers

Use image google/cloud-sdk which has a preinstalled installation of gcloud and kubectl.

build:
  stage: build
  image: google/cloud-sdk
  services:
  - docker:dind
  script:
  # Make gcloud available
  - source /root/.bashrc
like image 148
Tobias Ernst Avatar answered Oct 08 '22 08:10

Tobias Ernst