2017年2月12日星期日

OpenShift_053:离线安装 OCP 3.4 之安装与配置 Jenkins

环境:OCP 3.4

1. 安装与配置 Jenkins (在 Master 机器上操作)
创建一个 admin 用户,并且赋予权限
htpasswd -b /etc/origin/master/htpasswd admin admin
oadm policy add-cluster-role-to-user admin admin

确认 jenkins template 存在
oc get template -n openshift |grep jenkins
输出如下:
jenkins-ephemeral                               Jenkins service, without persistent storage....                                    6 (all set)       6
jenkins-persistent                              Jenkins service, with persistent storage....                                       7 (all set)       7

确认 jenkins image stream 存在
oc get is -n openshift |grep jenkins
输出如下:
jenkins      172.30.98.122:5000/openshift/jenkins      latest,2,1                   3 weeks ago

确认 jenkins image stream tag 存在
oc edit template jenkins-persistent -n openshift
查找 JENKINS_IMAGE_STREAM_TAG
- description: Name of the ImageStreamTag to be used for the Jenkins image.
  displayName: Jenkins ImageStreamTag
  name: JENKINS_IMAGE_STREAM_TAG
  value: jenkins:latest
说明:value: jenkins:latest 表明是使用最新的 jenkins 版本,这里是 jenkins 2。

查看 jenkins image stream 内容 oc edit is jenkins -n openshift

2. 创建 jenkins 持久化存储 (在 Registry 机器上操作)
yum -y install nfs-utils
export volname=jenkins
mkdir -p /srv/nfs/${volname}
chown nfsnobody:nfsnobody /srv/nfs/${volname}
chmod 700 /srv/nfs/${volname}
echo "/srv/nfs/${volname} *(rw,sync,all_squash)" >> /etc/exports
systemctl restart rpcbind nfs-server nfs-lock nfs-idmap
showmount -e

3. 验证 NFS Server 创建成功(在 Node1 机器上操作)
mkdir -p /mnt/nfs
mount -t nfs nfs.example.com:/srv/nfs/jenkins /mnt/nfs
umount /mnt/nfs

4. 创建 PV (在 Master 机器上操作,如果出错,此步需要重做)
echo '{
  "apiVersion": "v1",
  "kind": "PersistentVolume",
  "metadata": {
    "name": "jenkins-volume"
  },
  "spec": {
    "capacity": {
        "storage": "5Gi"
        },
    "accessModes": [ "ReadWriteOnce" ],
    "nfs": {
        "path": "/srv/nfs/jenkins",
        "server": "nfs.example.com"
    }
  }
}' | oc create -f -

5.  创建 jenkins 项目
oc new-project sharedjenkins
oc project sharedjenkins
oc annotate namespace sharedjenkins openshift.io/node-selector='infra=yes' --overwrite

OCP 3.3 执行如下命令:
oc new-app jenkins-persistent -n sharedjenkins -p JENKINS_PASSWORD=admin

OCP 3.4 执行如下命令:
oc new-app jenkins-persistent -n sharedjenkins
注意,OCP 3.4 以后 Jenkins 认证和 OCP 认证集成到一起了,因此不再需要 -p 参数。

确认 pvc 创建并绑定成功
oc get pvc
输出如下:
NAME      STATUS    VOLUME           CAPACITY   ACCESSMODES   AGE
jenkins   Bound     jenkins-volume   5Gi        RWO           1m

6. 确认安装配置 Jenkins 成功
oc get pod
输出如下:
NAME              READY     STATUS    RESTARTS   AGE
jenkins-1-lxdwn   1/1       Running   0          6m

http://jenkins-sharedjenkins.apps.example.com






7.  如果出错,执行以下命令清除,等待一分钟,然后重新把上述步骤做一遍
oc delete dc  jenkins
oc delete route jenkins
oc delete pvc jenkins
oc delete sa jenkins
oc delete rolebinding jenkins_edit
oc delete service jenkins-jnlp
oc delete service jenkins
oc delete project sharedjenkins

没有评论: