美文网首页
OpenShift修改subdomain域名

OpenShift修改subdomain域名

作者: ragpo | 来源:发表于2018-09-08 16:29 被阅读0次

需求

在客户的已经准备好上线的OpenShift 3.9集群中提出修改域名需求,因此先在本人的自己测试环境进行了验证,过程如下,并且还有一些坑,并进行了记录;将ocp6修改为ocp7。

修改方式

修改的方式有两种:

  • 在master节点修改/etc/origin/master/master-config.yaml文件:

    routingConfig: subdomain: apps.test.ocp6.com

  • 修改deploy节点上的/etc/ansible/hosts文件:

    openshift_master_default_subdomain=apps.test.ocp6.com

第一种修改方式:

  • 在master节点修改/etc/origin/master/master-config.yaml文件,如果是多个master节点的情况下,每个master节点修需要修改,由原来的apps.test.ocp6.com,修改为apps.test.ocp7.com
routingConfig:
  subdomain: apps.test.ocp7.com
  • 重启master服务
systemctl restart atomic-openshift-master-api.service  atomic-openshift-master-controllers.service
  • 观察此时的route,都还是ocp6.
[root@local2-ocp3.9-master1-test.com ~]# oc get route --all-namespaces
NAMESPACE         NAME               HOST/PORT                                     PATH      SERVICES           PORT      TERMINATION          WILDCARD
default           docker-registry    docker-registry-default.apps.test.ocp6.com              docker-registry    <all>     passthrough          None
default           registry-console   registry-console-default.apps.test.ocp6.com             registry-console   <all>     passthrough          None
jenkins           jenkins            jenkins-jenkins.apps.test.ocp6.com                      jenkins            <all>     edge/Redirect        None
logging           logging-kibana     kibana.apps.test.ocp6.com                               logging-kibana     <all>     reencrypt/Redirect   None
openshift-infra   hawkular-metrics   hawkular-metrics.apps.test.ocp6.com                     hawkular-metrics   <all>     reencrypt            None
  • 此时需要更新对应服务的route,更新有分为两种方式,一种是直接在原来的route上修改,一种是重新创建。

  • 第一种是在原先的route上进行修改,比较方便:

  1. 在界面上进行,修改registry-console的hostname为ocp7,保存:


    image-20180617133449499.png
  2. 在本机增加对应到route节点的域名解析
172.16.37.43 registry-console-default.apps.test.ocp7.com</pre>
  1. 到任意master节点上修改oauthclient cockpit-oauth-client,我直接新增了https://registry-console-default.apps.test.ocp7.com,也可以直接修改。这样这个两个地址都能访问,前提是ocp6的route在。
[root@local2-ocp3.9-master1-test.com ~]# oc edit oauthclient cockpit-oauth-client
oauthclient "cockpit-oauth-client" edited
[root@local2-ocp3.9-master1-test.com ~]# oc get  oauthclient cockpit-oauth-client -o yaml
apiVersion: oauth.openshift.io/v1
kind: OAuthClient
metadata:
 annotations:
 openshift.io/generated-by: OpenShiftNewApp
 creationTimestamp: 2018-06-17T00:56:08Z
 labels:
 app: registry-console
 createdBy: registry-console-template
 name: cockpit-oauth-client
 resourceVersion: "31325"
 selfLink: /apis/oauth.openshift.io/v1/oauthclients/cockpit-oauth-client
 uid: 38adc129-71c9-11e8-ad8b-000c2906e131
redirectURIs:
- https://registry-console-default.apps.test.ocp6.com
- https://registry-console-default.apps.test.ocp7.com
secret: userKHwbcoPVQBTJDpiMKOC1BssLpw5Eq7SCKVS5TGC1BtWxbpsRIkj2uwdbhdCSkC7J
  1. 访问域名地址即可。
image-20180617134156512.png
  • 第二种是为了防止修改错误,而重新创建一个新进行验证,创建新的可以在页面上进行,也可以在命令行里面进行,但是route的名称相关信息不能和原先的route冲突,需要注意的是有的route是带证书的,需要参考原先的route进行复制。
  1. 界面上操作就打开原先的registry-console route,再打开一个窗口进行创建新的route,除了名称不一样,其它的信息从原先的route复制过来即可:


    image-20180617134823267.png
    image-20180617134848876.png
  1. 如果从命令行操作就更方便了,以下命令主要是将原先的原先的route信息通过yaml文件导出,然后修改成现在新的域名,最后通过oc create -f 文件,即可。
[root@local2-ocp3.9-master1-test.com ~]# oc get route
NAME               HOST/PORT                                     PATH      SERVICES           PORT               TERMINATION   WILDCARD
docker-registry    docker-registry-default.apps.test.ocp6.com              docker-registry    <all>              passthrough   None
registry-console   registry-console-default.apps.test.ocp7.com             registry-console   registry-console   passthrough   None
[root@local2-ocp3.9-master1-test.com ~]# oc get route registry-console -o yaml >> registry-console-2.yaml
[root@local2-ocp3.9-master1-test.com ~]# cat registry-console-2.yaml
apiVersion: route.openshift.io/v1
kind: Route
metadata:
 annotations:
 openshift.io/host.generated: "true"
 creationTimestamp: 2018-06-17T03:45:24Z
 name: registry-console
 namespace: default
 resourceVersion: "31000"
 selfLink: /apis/route.openshift.io/v1/namespaces/default/routes/registry-console
 uid: dde737e7-71e0-11e8-a3dd-000c2906e131
spec:
 host: registry-console-default.apps.test.ocp7.com
 port:
 targetPort: registry-console
 tls:
 termination: passthrough
 to:
 kind: Service
 name: registry-console
 weight: 100
 wildcardPolicy: None
status:
 ingress:
 - conditions:
 - lastTransitionTime: 2018-06-17T05:33:31Z
 status: "True"
 type: Admitted
 host: registry-console-default.apps.test.ocp7.com
 routerName: router
 wildcardPolicy: None
[root@local2-ocp3.9-master1-test.com ~]# oc create -f registry-console-2.yaml
  1. 最后还要记得修改oauthclient对应的服务的url,然后就可以访问页面了。

第二种修改方式

  • 直接修改hosts文件中对域名的定义字段,然后重新部署,除了cockpit-oauth-client的oauthclient需要手动修改为最新的域名地址外,其他的都不需要,否则registry-console的域名访问会有问题。
openshift_master_default_subdomain=apps.test.ocp6.com
  • 使用第二种方式进行修改会导致htpasswd的信息被清空,记得备份,等部署结束后再复制到原路径。

遇到的坑

  • 使用第一种方式时,几乎所有route都要手动修改,并且还要修改对应的oauthclient文件,否则无法访问,访问时会出现如下报错:


    ![image-20180617140929515.png](https://img.haomeiwen.com/i13962638/a4bea4cc614e2138.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  • 因为web页面上会加载监控和日志的访问地址,所以第一种方式部署时需要修改openshift-web-console项目里面的configmap信息,修改为ocp7,如果是采用第二种方式修改域名,则web-console的configmap会自动更新。
  • 在使用第二种方式时,openshift安装时会自动修改kibana的oauthclient,添加新的域名地址进去,但是registry-console不会,需要手动更新。

Jenkins页面跳转的问题

  • 当有使用openshift集成的Jenkins时,在openshift上点击pipeline的logs时跳转的页面为为原来域名的Jenkins,改了route也没用,我当时是将pipeline内容保留然后删除重建就可以了

  • 以下是红帽case提供的修改方法,没生效。

Is your jenkins instance deployed inside OpenShift using the Jenkins template or is it an external Jenkins instance? If it is deployed on OpenShift and configured from the Jenkins template, you should be able to set the JENKINS_ROOT_URL by navigating to the Deployments > jenkins  > Actions > Edit YAML and adding a new environment variable and setting it's value to your Jenkins domain name. Please see the attached screenshot [1] for an example of where you can configure the JENKINS_ROOT_URL environment variable.

相关文章

网友评论

      本文标题:OpenShift修改subdomain域名

      本文链接:https://www.haomeiwen.com/subject/gmflgftx.html