【GCP】Qwiklabs の「Google Cloud Solutions I: Scaling Your Infrastructure」を勉強しています~Kubernetes Engine での Jenkins の設定~

Kubernetes Engine での Jenkins の設定 GCP
Kubernetes Engine での Jenkins の設定

Qwiklabs の「Google Cloud Solutions I: Scaling Your Infrastructure」を進めていきたいと思います。

Kubernetes Engine での Jenkins の設定

概要

Kubernetes Engine で Jenkins を設定する方法を学びます。

コマンド

環境を準備する

gcloud config set compute/zone us-east1-d
git clone https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes.git
cd continuous-deployment-on-kubernetes
Kubernetes クラスタを作成する
gcloud container clusters create jenkins-cd --num-nodes 2 --machine-type n1-standard-2 --scopes "https://www.googleapis.com/auth/projecthosting,cloud-platform"
gcloud container clusters list
gcloud container clusters get-credentials jenkins-cd
kubectl cluster-info

Helm をインストールする

wget https://storage.googleapis.com/kubernetes-helm/helm-v2.9.1-linux-amd64.tar.gz
tar zxfv helm-v2.9.1-linux-amd64.tar.gz
cp linux-amd64/helm .
kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=$(gcloud config get-value account)
kubectl create serviceaccount tiller --namespace kube-system
kubectl create clusterrolebinding tiller-admin-binding --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
./helm init --service-account=tiller
./helm repo update
./helm version

Jenkins を構成してインストールする

./helm install -n cd stable/jenkins -f jenkins/values.yaml --version 0.16.6 --wait
kubectl get pods
export POD_NAME=$(kubectl get pods -l "component=cd-jenkins-master" -o jsonpath="{.items[0].metadata.name}")
echo $POD_NAME
kubectl port-forward $POD_NAME 8080:8080 >> /dev/null &
kubectl get svc

Jenkins に接続する

下記のコマンドを実行して、adminパスワードを取得します。

printf $(kubectl get secret cd-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo

Cloud Shell で「ウェブでプレビュー」をクリックします。
「ポート8080でプレビュー」をクリックします。
ユーザー名「admin」と上記パスワードでログインします。

まとめ

Kubernetes Engine で Jenkins を設定する方法を学びました。
Helm については別途調べたほうがよさそうです。

https://www.papacoder.net/gcp-training-free-campaign/

コメント

タイトルとURLをコピーしました