Bienvenue dans une « série », un format qui comprend plusieurs articles et/ou vidéos Youtube dans lesquels on aborde un sujet dans sa globalité.
Aujourd’hui on va installer Jenkins X sur Kubernetes. L’installation de Kubernetes va être faite sur GKE via l’utilitaire fourni par Jenkins X qui est jx
.
Pour installer Jenkins X dans notre cluster Kubernetes, on va d’abord installer le binaire jx
.
Ensuite, grâce à jx
on va boostraper notre cluster GKE et configurer notre instance Jenkins X pour ensuite la tester via un workflow GitOps basique.
Installer le binaire jx sur Linux
Pour ça, on va utiliser l’outil fourni qui est jx :
1. On télécharge l’archive compressée du binaire jx
avec curl
et on pipe (|
) le tout vers la commande tar
:
$: curl -L "https://github.com/jenkins-x/jx/releases/download/$(curl --silent "https://github.com/jenkins-x/jx/releases/latest" | sed 's#.*tag/\(.*\)\".*#\1#')/jx-linux-amd64.tar.gz" | tar xzv "jx"
2. On bouge le binaire extrait vers notre path d’exécutables :
$: sudo mv jx /usr/local/bin
3. On affiche la version de jx
:
$: jx --version
Bootstraper un cluster Kubernetes
On va maintenant utiliser jx
pour bootstraper notre cluster GKE. Pour créer un cluster GKE vous devez avoir un projet Google Cloud. Le guide pour créer un projet se trouve dans la documentation Google Cloud.
On demande à jx
de nous créer ce cluster GKE :
$: jx create cluster gke --skip-installation
Une fois l’installation du cluster terminée, récupérez les identifiants de connexion à celui-ci avec gcloud
et vérifiez que vous pouvez lister les namespaces :
$: gcloud container clusters list
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
buffalotreasure europe-west1-b 1.14.10-gke.27 xx.xx.xx.xx n1-standard-2 1.14.10-gke.27 3 RUNNING
$: gcloud container clusters get-credentials buffalotreasure --zone europe-west1-b
Fetching cluster endpoint and auth data.
kubeconfig entry generated for buffalotreasure.
$: kubectl get ns
default
kube-node-lease
kube-public
kube-system
Installer Jenkins X sur le cluster Kubernetes
Pour lancer toute l’installation de Jenkins X sur votre cluster GKE, utilisez la commande jx boot
et suivez les instructions au fur et à mesure.
Plusieurs paramètres vont vous être demandés, notamment un token Github pour le bot jx que vous pouvez préparer d’avance sur la page suivante :
https://github.com/settings/tokens/new?scopes=repo,read:user,read:org,user:email,write:repo_hook,delete_repo
On lance maintenant notre jx boot
(l’output est volontairement réduit) :
$: jx boot
Creating boot config with defaults, as not in an existing boot directory with a git repository.
No Jenkins X pipeline file jenkins-x.yml or no jx boot requirements file jx-requirements.yml found. You are not running this command from inside a Jenkins X Boot git clone
To continue we will clone https://github.com/jenkins-x/jenkins-x-boot-config.git @ master to jenkins-x-boot-config
? Do you want to clone the Jenkins X Boot Git repository? Yes
Cloning https://github.com/jenkins-x/jenkins-x-boot-config.git @ master to jenkins-x-boot-config
fetching branch master
[...]
Currently connected cluster is buffalotreasure in europe-west1-b in project blackcreeper-network-learning
? Do you want to jx boot the buffalotreasure cluster? Yes
? Git Owner name for environment repositories : KrustyHack
Environment repos will be private, if you want to create public environment repos, please set environmentGitPublic to true in jx-requirements.yml
? Comma-separated git provider usernames of approvers for development environment repository : KrustyHack
Locking version stream https://github.com/jenkins-x/jenkins-x-versions.git to release v1.0.424. Jenkins X will use this release rather than master to resolve all versions from now on.
writing the following to the OWNERS file for the development environment repository:
approvers:
- KrustyHack
reviewers:
- KrustyHack
WARNING: TLS is not enabled so your webhooks will be called using HTTP. This means your webhook secret will be sent to your cluster in the clear. See https://jenkins-x.io/docs/getting-started/setup/boot/#ingress for more information
? Do you wish to continue? Yes
Verifying the kubernetes cluster before we try to boot Jenkins X in namespace: jx
Trying to lazily create any missing resources to get the current cluster ready to boot Jenkins X
Attempting to lazily create the deploy namespace jx
Namespace jx created
[...]
? Jenkins X Admin Username : admin
? Jenkins X Admin Password [? for help] : *****
? Pipeline bot Git username : jx
? Pipeline bot Git email address : jx@blackcreeper.com
? Pipeline bot Git token [? for help] : ****************************************
Generated token XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, to use it press enter.
This is the only time you will be shown it so remember to save it
? HMAC token, used to validate incoming webhooks. Press enter to use the generated token [? for help]
? Do you want to configure an external Docker Registry? No
[...]
Pushed Git repository to https://github.com/KrustyHack/environment-buffalotreasure-dev
Validating git repository for production environment at URL https://github.com/KrustyHack/environment-buffalotreasure-production.git
Using Git provider github at https://github.com
? Using Git user name: jx
? Using organisation: KrustyHack
Creating repository KrustyHack/environment-buffalotreasure-production
Creating Git repository KrustyHack/environment-buffalotreasure-production
Pushed Git repository to https://github.com/KrustyHack/environment-buffalotreasure-production
Validating git repository for staging environment at URL https://github.com/KrustyHack/environment-buffalotreasure-staging.git
Using Git provider github at https://github.com
? Using Git user name: jx
? Using organisation: KrustyHack
Creating repository KrustyHack/environment-buffalotreasure-staging
Creating Git repository KrustyHack/environment-buffalotreasure-staging
Pushed Git repository to https://github.com/KrustyHack/environment-buffalotreasure-staging
Environment git repositories look good
[...]
Verifying the git config
Verifying username jx at git server github at https://github.com
Found 2 organisations in git server https://github.com: ProximisFR, blackcreeper-network
Validated pipeline user jx on git server https://github.com
Git tokens seem to be setup correctly
Installation is currently looking: GOOD
Using namespace 'jx' from context named 'gke_blackcreeper-network-learning_europe-west1-b_buffalotreasure' on server 'https://xx.xx.xx.xx'.
Et voilà, notre instance Jenkins X est disponible est prête à l’emploi. Vous pouvez vérifier cela en listant les pods dans le namespace jx
:
$: kubectl get po
NAME READY STATUS RESTARTS AGE
crier-6c4944b868-v9q55 1/1 Running 0 21m
deck-7f5c64b45d-c86zl 1/1 Running 0 21m
deck-7f5c64b45d-shq9c 1/1 Running 0 21m
hook-647f968ffb-f577k 1/1 Running 0 21m
hook-647f968ffb-wx94c 1/1 Running 0 21m
horologium-9fdcd6b57-6dqsg 1/1 Running 0 21m
jenkins-6f7d67c75f-ndmh4 1/1 Running 0 21m
jenkins-x-chartmuseum-d87cbb789-wj6tl 1/1 Running 0 21m
jenkins-x-controllerrole-6464899d78-7dvll 1/1 Running 0 21m
jenkins-x-docker-registry-69d666d455-xsk59 1/1 Running 0 21m
jenkins-x-heapster-6c8b894c48-5r4hm 2/2 Running 0 21m
jenkins-x-nexus-549cd5b574-hdq4j 1/1 Running 0 21m
pipeline-7dff794486-sll4t 1/1 Running 0 21m
pipelinerunner-85d458d56c-jr44x 1/1 Running 0 21m
tekton-pipelines-controller-88c7cd9d5-4fvvt 1/1 Running 0 21m
tide-6bcf8f9f7f-mlxzk 1/1 Running 0 21m
Tous les composants principaux sont là et 3 repositories git ont été créés automatiquement sur votre compte Github. Nous verrons par la suite comment créer notre premier projet de CI/CD avec Jenkins X. Mais ça, c’est pour le prochain article.