2016年3月18日星期五

OpenShift_008:离线安装 OSE 3.1 之七:配置 OSE 3.1

环境:OS X EI Capitan 10.11.3 + Open Shift Enterprise 3.1

以下操作均在 Master 节点上执行

1. 安装 httpd 相关工具
yum -y install httpd-tools;

2. 创建httpd访问时所需的用户名密码
htpasswd -cb /etc/origin/master/users.htpasswd redhat welcome1 ;

3. 修改访问方式为 httpd 的基本校验方式
cp /etc/origin/master/master-config.yaml /etc/origin/master/master-config.yaml.bak.$(date "+%Y%m%d%H%M%S");
sed -i 's/DenyAllPasswordIdentityProvider/HTPasswdPasswordIdentityProvider/g' /etc/origin/master/master-config.yaml;
sed -i '/PasswordIdentityProvider/a\      file: /etc/origin/master/users.htpasswd' /etc/origin/master/master-config.yaml ;
sed -i 's/.*subdomain.*/  subdomain: apps.example.com/' /etc/origin/master/master-config.yaml ;
systemctl restart atomic-openshift-master;

4. 添加 router
(1) 添加 router
oc project default;
oc label node node1.example.com infra="yes"
oadm router ose-master --replicas=1 \
    --credentials='/etc/origin/master/openshift-router.kubeconfig' \
    --images='registry.example.com:5000/openshift3/ose-${component}:${version}' \
--selector='infra=yes' --service-account=router ;
(2) 测试
oc get node
直到出现一个 ose-master-1-XXX 的 pod 状态为 Running 时,表示创建成功。
输出如下:

5. 添加 registry
(1) 添加 registry
oadm registry --create --credentials=/etc/origin/master/openshift-registry.kubeconfig ;
(2) 测试
oc get node
直到出现一个 docker-registry-1-XXX 的 pod 状态为 Running 时,表示创建成功.
输出如下:

6. 添加 image stream
(1)把原有的 image stream 删除
for i in $(oc get is -n openshift --no-headers|awk '{print $1}') ; do oc delete is $i -n openshift; done;
(2)替换 registry.access.redhat.com 为 registry.example.com:5000
REDHAT_REG="registry.access.redhat.com";
PRIVATE_REG="registry.example.com:5000";
sed s/"${REDHAT_REG}"/"${PRIVATE_REG}"/g  /usr/share/openshift/examples/image-streams/image-streams-rhel7.json |sed '/"creationTimestamp": null/a\\t,"annotations": {"openshift.io/image.insecureRepository": "true"}' |oc create -n openshift -f - ;
(2)测试
oc get images
输出如下:

7. 验证 Web Console
(1)配置本机的 dns 地址, 指向可访问到 master.example.com 的地址
sed -i '1 i\192.168.56.105' /etc/resolv.conf
(2)在浏览器中访问 https://master.example.com:8443 redhat/welcome1
(3)New Project
(4)选择 php:5.6 sti 镜像
(5)输入当前应用的项目名及源码地址
(6)Continue to overview
(7)等待编译,在左侧的Browse->Events中查看日志
(8)成功部署后, 在 Overview 页面, 点击上/下方向键可调整 pod 数量
(9)点击SERVICE下的域名, 可访问当前服务
(10)点击 Overview -> Topology View标签, 可直观的显示各部分内容
(11)添加 git hook 触发 Openshift 自动部署
  在 master 节点获取 build web hook trigger
OSE_PRJ=;
OSE_APP=;
OSE_SEC=$(oc get bc $OSE_APP -o yaml -n $OSE_PRJ|grep generic -A 1|grep secret|awk -F ': ' '{print $2}');
BC_URL=    "https://master.example.com:8443/oapi/v1/namespaces/$OSE_PRJ/buildconfigs/$OSE_APP/webhooks/$OSE_SEC/generic";
  在 git.example.com 机器中, 将 BC_URL 加入到 git 的项目中
echo "curl -k -H 'Content-Type: application/json' -X POST $BC_URL" > /opt/git/repo/cakephp.git/hooks/post-receive;
chmod +x /opt/git/repo/cakephp.git/hooks/post-receive;

没有评论: