openshift4 提供了一些CRD 來修改web console,方便我們作一些告示和自定義幫助鏈接、第三方平臺跳轉。
需要注意的是有限修改,改一些為了便捷可視化的內容,畢竟想一想,要在左邊加個菜單可不是那么簡單的事情。
一共有4個CRD
ConsoleNotifications :定義頁面抬頭顏色和告示
ConsoleExternalLogLinks :pod 日志外部跳轉鏈接
ConsoleLinks :自定義外部鏈接
ConsoleCLIDownloads :自定義常用cli工具下載
另外從 4.7 開始已經增加了中文支持(還有日文),對于新用戶更友好一些。
下面具體介紹這4個 CRD 怎么用,及其效果。
以下操作內容均需 cluster-admin 權限。
ConsoleNotifications
這個能干啥呢,比如給不同的環境整個不一樣的顏色,免得不小心混了。或者寫點什么告訴你的小伙伴生產環境悠著點,還可以寫上你隊友的電話號碼。又或者來個幫助文檔的鏈接,都是ok的。
后面會介紹另外一種方式可以添加更多鏈接。
[root@bastion console-crd]# cat ConsoleNotification.yaml
apiVersion: console.openshift.io/v1
kind: ConsoleNotification
metadata:
name: example
spec:
text: 這是生產環境,請遵循變更流程謹慎操作。
location: BannerTop ##Other options are BannerBottom, BannerTopBottom
link:
href: 'https://www.example.com'
text: 有不會的點這里
color: '#fff'
backgroundColor: red
text: 顯示的文字內容。
location: BannerTop 顯示在上面,也可以在下面或者上下一起(看著會有點奇怪,哈)。
link: 超鏈接了,可以用了跳轉幫助文檔頁面。
color: 字體顏色。
backgroundColor: 背景色。
顏色可以直接寫英文,也可以寫編碼,這邊有個對照表。
http://xh.5156edu.com/page/z1015m9220j18754.html
比如
MediumBlue 中藍色 #0000CD
Gold 金色 #FFD700
ConsoleExternalLogLinks
針對將日志轉發到外部平臺的情況。
現在很多客戶都建設了大數據平臺,會要求將應用日志發送到統一的日志平臺。
openshift 頁面默認的日志跳轉是指向平臺內部kibana地址的(前提是安裝了EFK)。
如下圖
通過 ConsoleExternalLogLinks 可以定義好外部的日志查詢地址和規則,一鍵跳轉,不需要到日志平臺再去輸入查詢規則。
我沒有去實際做轉發日志到外部日志服務器,只測試下跳轉能力。
[root@bastion console-crd]# cat ConsoleExternalLogLink.yaml
apiVersion: console.openshift.io/v1
kind: ConsoleExternalLogLink
metadata:
name: example
spec:
hrefTemplate: >-
https://example.com/logs?resourceName=${resourceName}&containerName=${containerName}&resourceNamespace=${resourceNamespace}&podLabels=${podLabels}
text: Example Logs
導入后,log 頁面多了一個跳轉按鈕。按鈕名稱就是上面的 text 內容。
ConsoleLinks
添加自定義超鏈接。
有幾個地方可以加,分別是 User Menu,Help Menu,Application Menu,NamespaceDashboard
User Menu & Help Menu
這兩個可配置參數是一樣的,location 不同而已。 可用于鏈接到用戶文檔、幫助文檔。
[root@bastion console-crd]# cat ConsoleLink-help.yaml
apiVersion: console.openshift.io/v1
kind: ConsoleLink
metadata:
name: openshift-help-zh
spec:
href: 'https://access.redhat.com/documentation/zh-cn/openshift_container_platform/4.7/'
location: HelpMenu
text: Openshift 官方幫助文檔
Application Menu
用于鏈接到 openshift 平臺組件或者其他平臺地址,如git代碼庫地址,監控等。
像 openshift GitOps operator, EFK operator 部署完成后,自動添加了兩個 Application Menu
比上面的兩個 menu 多了兩個參數,section 可以分類,imageURL可以添加一個小logo
[root@bastion console-crd]# cat ConsoleLink-Application.yaml
apiVersion: console.openshift.io/v1
kind: ConsoleLink
metadata:
name: applicationmenu-k8s
spec:
applicationMenu:
imageURL: data:image/png;base64,iVBORw0KGgoAAAAN........
section: Kubernetes Blogs
href: 'https://github.com/cai11745/k8s-ocp-yaml'
location: ApplicationMenu
text: Caifeng's k8s Blog
imageURL 可以是一個http的在線圖片, http://xxx/xx.png
也可以是png 轉成base64,不要用太大的圖,我這邊用了一個k8s的logo,轉完也很多行,我就不貼了。
隨便搜一下 png to base64 就會出來很多在線工具。
https://onlinepngtools.com/convert-png-to-base64
https://www.base64-image.de/
效果如下
NamespaceDashboard
這是加到 project 頁面的,可以指定哪些 project 看到。
以下指定了 default,demo,demo-cicd 三個project,在 Home -> project 詳情頁可以看到配置的鏈接。
[root@bastion console-crd]# cat ConsoleLink-namspace.yaml
apiVersion: console.openshift.io/v1
kind: ConsoleLink
metadata:
name: example-namespace-dashboard
spec:
href: 'https://www.example.com'
location: NamespaceDashboard
text: Namespace Dashboard Link
namespaceDashboard:
namespaces:
- default
- demo
- demo-cicd
ConsoleCLIDownloads
用于配置一些 client 工具的下載說明和下載地址。
系統已經內置了 helm kam oc tkn 這些命令,不過他們的地址都是互聯網的,可以修改為我們內網的,或者添加新的工具下載地址。
[root@bastion console-crd]# oc get ConsoleCLIDownload
NAME DISPLAY NAME AGE
helm-download-links helm - Helm 3 CLI 2021-04-08T04:25:11Z
kam GitOps Application Manager 2021-05-10T02:40:34Z
oc-cli-downloads oc - OpenShift Command Line Interface (CLI) 2021-04-08T06:11:45Z
odo-cli-downloads odo - Developer-focused CLI for OpenShift 2021-04-08T06:11:45Z
tkn tkn - OpenShift Pipeline Command Line Interface (CLI) 2021-04-12T05:31:54Z
這些內容通過點擊右上角 “?”符號 -> Command Line Tools
跳轉到下載說明頁面
oc 命令的配置頁面,可以把 url 改成內網相應內容。
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: console.openshift.io/v1
kind: ConsoleCLIDownload
metadata:
creationTimestamp: "2021-04-08T06:11:45Z"
generation: 1
name: oc-cli-downloads
resourceVersion: "116909"
selfLink: /apis/console.openshift.io/v1/consoleclidownloads/oc-cli-downloads
uid: 7cd6735b-3e7c-45b1-b23a-de147d0dcf1b
spec:
description: |
With the OpenShift command line interface, you can create applications and manage OpenShift projects from a terminal.
The oc binary offers the same capabilities as the kubectl binary, but it is further extended to natively support OpenShift Container Platform features.
displayName: oc - OpenShift Command Line Interface (CLI)
links:
- href: https://downloads-openshift-console.apps.ocp4.example.com/amd64/linux/oc.tar
text: Download oc for Linux for x86_64
- href: https://downloads-openshift-console.apps.ocp4.example.com/amd64/mac/oc.zip
text: Download oc for Mac for x86_64
- href: https://downloads-openshift-console.apps.ocp4.example.com/amd64/windows/oc.zip
text: Download oc for Windows for x86_64
- href: https://downloads-openshift-console.apps.ocp4.example.com/arm64/linux/oc.tar
text: Download oc for Linux for ARM 64 (unsupported)
- href: https://downloads-openshift-console.apps.ocp4.example.com/ppc64le/linux/oc.tar
text: Download oc for Linux for IBM Power, little endian
- href: https://downloads-openshift-console.apps.ocp4.example.com/s390x/linux/oc.tar
text: Download oc for Linux for IBM Z
- href: https://downloads-openshift-console.apps.ocp4.example.com/oc-license
text: LICENSE
參考鏈接
https://www.openshift.com/blog/openshift-4-2-console-customization