阿里云容器服务Kubernetes之Jenkins X(1)-安装部署实践篇

本文的部署实践过程参考了云栖文章 如何在阿里云容器服务上搭建Jenkins X并记录了更详细的过程及日志输出。

下面我们开始介绍如何在阿里云容器服务Kubernetes上快速安装部署Jenkins X。

1. 首先,需要在 阿里云容器服务控制台 创建一个Kubernetes集群,本次实践使用的环境信息如下:

master1 192.168.0.134
master2 192.168.0.135
master3 192.168.0.136
worker1 192.168.0.137

2. 登录worker1节点(也可以使用集群外的任意ecs环境)并初始化helm client
# mkdir $HOME/.kube
# scp [email protected]:/etc/kubernetes/kube.conf $HOME/.kube/config
[email protected]'s password:
kube.conf                                                                                                                                       100% 5472     8.4MB/s   00:00
# scp [email protected]:/usr/local/bin/helm /usr/local/bin/helm
[email protected]'s password:
helm                                                                                                                                            100%   29MB 104.0MB/s   00:00
# helm init --client-only
Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.
Not installing Tiller due to 'client-only' flag having been set
Happy Helming!
3. 安装 git。
yum install git -y
4. 安装jx客户端
# curl -L https://github.com/jenkins-x/jx/releases/download/v1.3.464/jx-linux-amd64.tar.gz | tar xzv
# mv jx /usr/local/bin
# jx version
Using helmBinary helm with feature flag: none
NAME               VERSION
jx                 1.3.464
Kubernetes cluster v1.11.2
kubectl            v1.11.2
helm client        v2.9.1+g20adb27
helm server        v2.9.1+g20adb27
git                git version 1.8.3.1
A new jx version is available: 1.3.470
? Would you like to upgrade to the new jx version? No
5. 下载 cloud-environments 云环境配置文件
# mkdir -p ~/.jx
# cd ~/.jx
# git clone https://github.com/haoshuwei/cloud-environments.git
正克隆到 'cloud-environments'...
remote: Enumerating objects: 526, done.
remote: Total 526 (delta 0), reused 0 (delta 0), pack-reused 526
接收对象中: 100% (526/526), 229.61 KiB | 261.00 KiB/s, done.
处理 delta 中: 100% (263/263), done.
6. 安装jenkins-x-platform到Kubernetes集群
# jx install --provider=kubernetes --domain aliyunk8s.com


访问日志中提示的GitHub URL 并生成API Token:

https://github.com/settings/tokens/new?scopes=repo,read:user,read:org,user:email,write:repo_hook,delete_repo


新打开一个终端窗口查看jenkins-x-platform各个组件的安装情况:

# kubectl get ing -n jx
NAME              HOSTS                              ADDRESS         PORTS     AGE
chartmuseum       chartmuseum.jx.aliyunk8s.com       xx.xx.xxx.xxx   80        49s
docker-registry   docker-registry.jx.aliyunk8s.com   xx.xx.xxx.xxx   80        49s
jenkins           jenkins.jx.aliyunk8s.com           xx.xx.xxx.xxx   80        48s
monocular         monocular.jx.aliyunk8s.com         xx.xx.xxx.xxx   80        49s
nexus             nexus.jx.aliyunk8s.com             xx.xx.xxx.xxx   80        49s

绑定hosts:

# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
xx.xx.xxx.xxx chartmuseum.jx.aliyunk8s.com
xx.xx.xxx.xxx docker-registry.jx.aliyunk8s.com
xx.xx.xxx.xxx jenkins.jx.aliyunk8s.com
xx.xx.xxx.xxx monocular.jx.aliyunk8s.com
xx.xx.xxx.xxx nexus.jx.aliyunk8s.com

查看jenkins-x-platform组件的安装情况:

[root@iZj6cbxzol17fruawjffz1Z ~]# kubectl get pod -n jx
NAME                                             READY     STATUS             RESTARTS   AGE
jenkins-67d7cc5fcd-x6686                         1/1       Running            0          8m
jenkins-x-chartmuseum-84b895f4c5-d2dgc           1/1       Running            0          8m
jenkins-x-docker-registry-6b6f6d67b6-kn9ml       1/1       Running            0          8m
jenkins-x-heapster-65fd697bb-4czvz               2/2       Running            0          8m
jenkins-x-mongodb-784f66c466-zz429               0/1       Pending            0          8m
jenkins-x-monocular-api-58796c57c9-xk8rs         0/1       CrashLoopBackOff   5          8m
jenkins-x-monocular-prerender-5848c74fdc-48ppm   1/1       Running            0          8m
jenkins-x-monocular-ui-c4467bdc5-ttbr6           1/1       Running            0          8m
jenkins-x-nexus-b7454965d-nvlqb                  1/1       Running            0          8m
pipelinecontroller-6b5b8d9f47-457xx              1/1       Running            0          8m

发现jenkins-x-mongodb和jenkins-x-monocular-api组件启动异常,这是因为jenkins-x-monocular-api依赖jenkins-x-mongodb, 而jenkins-x-mongodb在创建pvc资源时找不到default storage class而导致的;编辑mongodb-pvc.yaml创建新pvc:

# cat mongodb-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-x-mongodb
  namespace: jx
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: alicloud-disk-available
  resources:
    requests:
      storage: 20Gi
 # kubectl get pvc -n jx
NAME                        STATUS    VOLUME                   CAPACITY   ACCESS MODES   STORAGECLASS              AGE
jenkins                     Bound     d-j6c8mnao06oovpk0vy4h   30Gi       RWO            alicloud-disk-available   18m
jenkins-x-chartmuseum       Bound     d-j6c9szfy8smf4ak05hm9   20Gi       RWO            alicloud-disk-available   18m
jenkins-x-docker-registry   Bound     d-j6cc913ulnzfa7drkru9   100Gi      RWO            alicloud-disk-available   18m
jenkins-x-mongodb           Pending                                                                                18m
jenkins-x-nexus             Bound     d-j6cfrymuj8lrj2pvz3v0   20Gi       RWO            alicloud-disk-available   18m
# kubectl delete pvc jenkins-x-mongodb -n jx
persistentvolumeclaim "jenkins-x-mongodb" deleted
# kubectl create -f mongodb-pvc.yaml
persistentvolumeclaim/jenkins-x-mongodb created
# kubectl delete  pods jenkins-x-mongodb-784f66c466-zz429 -n jx
pod "jenkins-x-mongodb-784f66c466-zz429" deleted
# kubectl delete  pods jenkins-x-monocular-api-58796c57c9-xk8rs -n jx
pod "jenkins-x-monocular-api-58796c57c9-xk8rs" deleted

全部组件运行正常后可以看到jenkins-x-platform的安装进程进入下一步jenkins CLI API Token的配置:

根据提示获取token填入后, 安装部署完成:

7. 查看ingress暴露出来的服务url
# jx get urls
Name                      URL
jenkins                   http://jenkins.jx.aliyunk8s.com
jenkins-x-chartmuseum     http://chartmuseum.jx.aliyunk8s.com
jenkins-x-docker-registry http://docker-registry.jx.aliyunk8s.com
jenkins-x-monocular-api   http://monocular.jx.aliyunk8s.com
jenkins-x-monocular-ui    http://monocular.jx.aliyunk8s.com
nexus                     http://nexus.jx.aliyunk8s.com

访问http://jenkins.jx.aliyunk8s.com:
阿里云容器服务Kubernetes之Jenkins X(1)-安装部署实践篇_第1张图片
访问http://monocular.jx.aliyunk8s.com:
阿里云容器服务Kubernetes之Jenkins X(1)-安装部署实践篇_第2张图片
访问http://nexus.jx.aliyunk8s.com:
阿里云容器服务Kubernetes之Jenkins X(1)-安装部署实践篇_第3张图片
docker-registry服务的访问有问题(暂时未花过多时间调试), 但我们会在下一篇阿里云容器服务Kubernetes之Jenkins X(2)-自动化CICD实践篇中演示如何让jenkins x使用阿里云容器镜像服务来管理容器镜像;阿里云容器服务Kubernetes之Jenkins X(2)-自动化CICD实践篇 中也会使用jenkins x创建一个spring应用并演示如何使用GitOps的理念管理和发布一个云原生应用。

你可能感兴趣的:(阿里云容器服务Kubernetes之Jenkins X(1)-安装部署实践篇)