kubernetes-dashboard 语言设置为英文
Kubernetes Web UI 默认的配置下语言会跟着浏览器的语言走,也就是说你的浏览器语言是中文的话,面板的语言默认也是中文,并且无法通过面板上的设置来选择语言。大多数时候当然是母语最适合用户,但是像 k8s 这种系统,网上查到的资料大都是英文的,所以反倒是看到对应的中文术语的时候会让人愣一下,反应下这个中文对应的英文术语是什么。所以我个人更倾向将开发工具都默认设置为英文,很多情况下这反倒是
Kubernetes Web UI 默认的配置下语言会跟着浏览器的语言走,也就是说你的浏览器语言是中文的话,面板的语言默认也是中文,并且无法通过面板上的设置来选择语言。大多数时候当然是母语最适合用户,但是像 k8s 这种系统,网上查到的资料大都是英文的,所以反倒是看到对应的中文术语的时候会让人愣一下,反应下这个中文对应的英文术语是什么。所以我个人更倾向将开发工具都默认设置为英文,很多情况下这反倒是提高了我的工作效率。
既然 k8s 的面板默认没有提供语言的选择,有没有办法来切换呢?
在网上搜索了一番,貌似都没有特别成熟或者方便的办法,下面这个网址算是一个解决办法:
https://jimmysong.io/kubernetes-handbook/practice/dashboard-upgrade.html
设置接口的语言
我们看到现在 dashboard 的页面都已经被汉化了,当前支持英文、中文简体、中文繁体、日语,根据浏览器的语言自动切换的。如果想要强制设置 dashboard 中显示的语言,需要在 dahsboard 的 Deployment yaml 配置中增加如下配置:
env:
- name: ACCEPT_LANGUAGE
value: english
更简单的方式是,如果您使用的Chrome浏览器,则在浏览器中的配置中设置语言的顺序后刷新网页,dashboard将以您在Chrome中配置的首选语言显示。
完整示例
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------- Dashboard Secret ------------------- #
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-certs
namespace: kube-system
type: Opaque
---
# ------------------- Dashboard Service Account ------------------- #
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
---
# ------------------- Dashboard Role & Role Binding ------------------- #
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kubernetes-dashboard-minimal
namespace: kube-system
rules:
# Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create"]
# Allow Dashboard to create 'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["create"]
# Allow Dashboard to get, update and delete Dashboard exclusive secrets.
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]
verbs: ["get", "update", "delete"]
# Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
resources: ["configmaps"]
resourceNames: ["kubernetes-dashboard-settings"]
verbs: ["get", "update"]
# Allow Dashboard to get metrics from heapster.
- apiGroups: [""]
resources: ["services"]
resourceNames: ["heapster"]
verbs: ["proxy"]
- apiGroups: [""]
resources: ["services/proxy"]
resourceNames: ["heapster", "http:heapster:", "https:heapster:"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: kubernetes-dashboard-minimal
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: kubernetes-dashboard-minimal
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kube-system
---
# ------------------- Dashboard Deployment ------------------- #
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: kubernetes-dashboard
template:
metadata:
labels:
k8s-app: kubernetes-dashboard
spec:
containers:
- name: kubernetes-dashboard
image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.0
ports:
- containerPort: 8443
protocol: TCP
##设置语言为英文显示
env:
- name: ACCEPT_LANGUAGE
value: english
args:
- --auto-generate-certificates
# Uncomment the following line to manually specify Kubernetes API server Host
# If not specified, Dashboard will attempt to auto discover the API server and connect
# to it. Uncomment only if the default does not work.
# - --apiserver-host=http://my-address:port
volumeMounts:
- name: kubernetes-dashboard-certs
mountPath: /certs
# Create on-disk volume to store exec logs
- mountPath: /tmp
name: tmp-volume
livenessProbe:
httpGet:
scheme: HTTPS
path: /
port: 8443
initialDelaySeconds: 30
timeoutSeconds: 30
volumes:
- name: kubernetes-dashboard-certs
secret:
secretName: kubernetes-dashboard-certs
- name: tmp-volume
emptyDir: {}
serviceAccountName: kubernetes-dashboard
# Comment the following tolerations if Dashboard must not be deployed on master
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
---
# ------------------- Dashboard Service ------------------- #
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 31001
selector:
k8s-app: kubernetes-dashboard
---
# Create ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kube-system
可以说是两种方法:一种是部署 dashboard 的时候强制指定为英文,也就是说会无视用户浏览器的语言配置,默认都返回英文的页面;另一种是设置浏览器的语言,将浏览器的语言设置为英文即可。
两种方法都有弊端,前者我们必须有 k8s dashboard 的部署控制权,这在很多时候是不可能的,另外,这也剥夺了用户使用本地化语言的权力;后者的话会导致浏览器请求所有的网页都按照英文来请求,这也不是我们所期待的。
有没有办法能够只让 k8s dashboard 请求英文网页,而不影响其他网站呢,经过一番研究我找到了一个相对不算特别复杂的方法。
首先安装一个 chrome 插件:Locale Switcher。打开 k8s dashboard 可以通过点击插件图标来切换语言,选择英文即可。
不过这个插件默认是全局生效的,所以一但点击英文,所有的网站请求都会默认有限请求英文的网站。虽然可以通过点击中文来切换回来,比起到浏览器的语言设置里修改语言已经简单了许多。但是毕竟我们不想总是这样的手工控制语言切换。
其实chrome是可以指定插件可以生效的网站范围的,右键点击插件图标,选择管理扩展进程就会跳转到插件的管理页面,会看到一个条目是 有权访问的网站 ,在此条目下选择 在特定网站上 ,并在下面填写你的 k8s dashboard 个地址,形如 https://your-host:port/* (注意 *)。
这样将插件选择成英文后,再次刷新你的 k8s dashboard 页面时,语言就默认是英文了,而其他网站的语言设置却不受插件的影响,如果你嫌插件的图标占地方,甚至可以选择隐藏图标,因为大概率你以后不需要再点击这个图标了。
当然,这个方法也支持将其他网站的请求语言设置为不同的语言,不仅限于 k8s dashboard 。
更多推荐
所有评论(0)