Switch language name 'zh' to 'zh-cn'
This is the first step to rename 'zh' to 'zh-cn'. There are several reasons why we rename the language name.
- The upstream docsy theme changed the language name, leading to many warnings during site build;
The side-effect is that the i18n strings are no longer working.
- We believe renaming the language is the right thing to do, because this move can make room for other variants of Chinese language, such as 'zh-tw', 'zh-sg' etc.
There would be several follow-ups to this PR, such as fixing the intra-site links, adding redirects etc.
We will lock up changes to zh/zh-cn pages for the moment, until this one gets in.
This PR is based on commit cdad0a7342.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
title: "配置"
|
||||
weight: 30
|
||||
---
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
title: "示例:配置 java 微服务"
|
||||
weight: 10
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "Example: Configuring a Java Microservice"
|
||||
weight: 10
|
||||
---
|
||||
-->
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: "互动教程 - 配置 java 微服务"
|
||||
weight: 20
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "Interactive Tutorial - Configuring a Java Microservice"
|
||||
weight: 20
|
||||
---
|
||||
-->
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="zh">
|
||||
|
||||
<body>
|
||||
|
||||
<link href="/docs/tutorials/kubernetes-basics/public/css/styles.css" rel="stylesheet">
|
||||
<link href="/docs/tutorials/kubernetes-basics/public/css/overrides.css" rel="stylesheet">
|
||||
<script src="https://katacoda.com/embed.js"></script>
|
||||
|
||||
<div class="layout" id="top">
|
||||
|
||||
<main class="content katacoda-content">
|
||||
<div class="katacoda">
|
||||
<div class="katacoda__alert">
|
||||
<!-- To interact with the Terminal, please use the desktop/tablet version -->
|
||||
如需要与终端交互,请使用台式机/平板电脑版
|
||||
</div>
|
||||
<div class="katacoda__box" id="inline-terminal-1" data-katacoda-id="kubernetes-bootcamp/9" data-katacoda-color="326de6" data-katacoda-secondary="273d6d" data-katacoda-hideintro="false" data-katacoda-prompt="Kubernetes Bootcamp Terminal" style="height: 600px;"></div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
---
|
||||
title: "使用 MicroProfile、ConfigMaps、Secrets 实现外部化应用配置"
|
||||
content_type: tutorial
|
||||
weight: 10
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "Externalizing config using MicroProfile, ConfigMaps and Secrets"
|
||||
content_type: tutorial
|
||||
weight: 10
|
||||
---
|
||||
-->
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
<!--
|
||||
In this tutorial you will learn how and why to externalize your microservice’s configuration. Specifically, you will learn how to use Kubernetes ConfigMaps and Secrets to set environment variables and then consume them using MicroProfile Config.
|
||||
-->
|
||||
在本教程中,你会学到如何以及为什么要实现外部化微服务应用配置。
|
||||
具体来说,你将学习如何使用 Kubernetes ConfigMaps 和 Secrets 设置环境变量,
|
||||
然后在 MicroProfile config 中使用它们。
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
<!--
|
||||
### Creating Kubernetes ConfigMaps & Secrets
|
||||
There are several ways to set environment variables for a Docker container in Kubernetes, including: Dockerfile, kubernetes.yml, Kubernetes ConfigMaps, and Kubernetes Secrets. In the tutorial, you will learn how to use the latter two for setting your environment variables whose values will be injected into your microservices. One of the benefits for using ConfigMaps and Secrets is that they can be re-used across multiple containers, including being assigned to different environment variables for the different containers.
|
||||
-->
|
||||
### 创建 Kubernetes ConfigMaps 和 Secrets {#creating-kubernetes-configmaps-secrets}
|
||||
在 Kubernetes 中,为 docker 容器设置环境变量有几种不同的方式,比如:
|
||||
Dockerfile、kubernetes.yml、Kubernetes ConfigMaps、和 Kubernetes Secrets。
|
||||
在本教程中,你将学到怎么用后两个方式去设置你的环境变量,而环境变量的值将注入到你的微服务里。
|
||||
使用 ConfigMaps 和 Secrets 的一个好处是他们能在多个容器间复用,
|
||||
比如赋值给不同的容器中的不同环境变量。
|
||||
|
||||
<!--
|
||||
ConfigMaps are API Objects that store non-confidential key-value pairs. In the Interactive Tutorial you will learn how to use a ConfigMap to store the application's name. For more information regarding ConfigMaps, you can find the documentation [here](/docs/tasks/configure-pod-container/configure-pod-configmap/).
|
||||
|
||||
Although Secrets are also used to store key-value pairs, they differ from ConfigMaps in that they're intended for confidential/sensitive information and are stored using Base64 encoding. This makes secrets the appropriate choice for storing such things as credentials, keys, and tokens, the former of which you'll do in the Interactive Tutorial. For more information on Secrets, you can find the documentation [here](/docs/concepts/configuration/secret/).
|
||||
-->
|
||||
ConfigMaps 是存储非机密键值对的 API 对象。
|
||||
在互动教程中,你会学到如何用 ConfigMap 来保存应用名字。
|
||||
ConfigMap 的更多信息,你可以在[这里](/zh/docs/tasks/configure-pod-container/configure-pod-configmap/)找到文档。
|
||||
|
||||
Secrets 尽管也用来存储键值对,但区别于 ConfigMaps 的是:它针对机密/敏感数据,且存储格式为 Base64 编码。
|
||||
secrets 的这种特性使得它适合于存储证书、密钥、令牌,上述内容你将在交互教程中实现。
|
||||
Secrets 的更多信息,你可以在[这里](/zh/docs/concepts/configuration/secret/)找到文档。
|
||||
|
||||
|
||||
<!--
|
||||
### Externalizing Config from Code
|
||||
Externalized application configuration is useful because configuration usually changes depending on your environment. In order to accomplish this, we'll use Java's Contexts and Dependency Injection (CDI) and MicroProfile Config. MicroProfile Config is a feature of MicroProfile, a set of open Java technologies for developing and deploying cloud-native microservices.
|
||||
-->
|
||||
### 从代码外部化配置
|
||||
外部化应用配置之所以有用处,是因为配置常常根据环境的不同而变化。
|
||||
为了实现此功能,我们用到了 Java 上下文和依赖注入(Contexts and Dependency Injection, CDI)、MicroProfile 配置。
|
||||
MicroProfile config 是 MicroProfile 的功能特性,
|
||||
是一组开放 Java 技术,用于开发、部署云原生微服务。
|
||||
|
||||
<!--
|
||||
CDI provides a standard dependency injection capability enabling an application to be assembled from collaborating, loosely-coupled beans. MicroProfile Config provides apps and microservices a standard way to obtain config properties from various sources, including the application, runtime, and environment. Based on the source's defined priority, the properties are automatically combined into a single set of properties that the application can access via an API. Together, CDI & MicroProfile will be used in the Interactive Tutorial to retrieve the externally provided properties from the Kubernetes ConfigMaps and Secrets and get injected into your application code.
|
||||
|
||||
Many open source frameworks and runtimes implement and support MicroProfile Config. Throughout the interactive tutorial, you'll be using Open Liberty, a flexible open-source Java runtime for building and running cloud-native apps and microservices. However, any MicroProfile compatible runtime could be used instead.
|
||||
-->
|
||||
CDI 提供一套标准的依赖注入能力,使得应用程序可以由相互协作的、松耦合的 beans 组装而成。
|
||||
MicroProfile Config 为 app 和微服务提供从各种来源,比如应用、运行时、环境,获取配置参数的标准方法。
|
||||
基于来源定义的优先级,属性可以自动的合并到单独一组应用可以通过 API 访问到的属性。
|
||||
CDI & MicroProfile 都会被用在互动教程中,
|
||||
用来从 Kubernetes ConfigMaps 和 Secrets 获得外部提供的属性,并注入应用程序代码中。
|
||||
|
||||
很多开源框架、运行时支持 MicroProfile Config。
|
||||
对于整个互动教程,你都可以使用开放的库、灵活的开源 Java 运行时,去构建并运行云原生的 apps 和微服务。
|
||||
然而,任何 MicroProfile 兼容的运行时都可以用来做替代品。
|
||||
|
||||
|
||||
## {{% heading "objectives" %}}
|
||||
|
||||
<!--
|
||||
* Create a Kubernetes ConfigMap and Secret
|
||||
* Inject microservice configuration using MicroProfile Config
|
||||
-->
|
||||
* 创建 Kubernetes ConfigMap 和 Secret
|
||||
* 使用 MicroProfile Config 注入微服务配置
|
||||
|
||||
|
||||
<!-- lessoncontent -->
|
||||
|
||||
<!--
|
||||
## Example: Externalizing config using MicroProfile, ConfigMaps and Secrets
|
||||
### [Start Interactive Tutorial](/docs/tutorials/configuration/configure-java-microservice/configure-java-microservice-interactive/)
|
||||
-->
|
||||
## 示例:使用 MicroProfile、ConfigMaps、Secrets 实现外部化应用配置
|
||||
### [启动互动教程](/zh/docs/tutorials/configuration/configure-java-microservice/configure-java-microservice-interactive/)
|
||||
@@ -0,0 +1,376 @@
|
||||
---
|
||||
title: 使用 ConfigMap 来配置 Redis
|
||||
content_type: tutorial
|
||||
---
|
||||
<!--
|
||||
reviewers:
|
||||
- eparis
|
||||
- pmorie
|
||||
title: Configuring Redis using a ConfigMap
|
||||
content_type: tutorial
|
||||
-->
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
<!--
|
||||
This page provides a real world example of how to configure Redis using a ConfigMap and builds upon the [Configure a Pod to Use a ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/) task.
|
||||
-->
|
||||
这篇文档基于[配置 Pod 以使用 ConfigMap](/zh/docs/tasks/configure-pod-container/configure-pod-configmap/)
|
||||
这个任务,提供了一个使用 ConfigMap 来配置 Redis 的真实案例。
|
||||
|
||||
|
||||
|
||||
## {{% heading "objectives" %}}
|
||||
|
||||
|
||||
<!--
|
||||
* Create a ConfigMap with Redis configuration values
|
||||
* Create a Redis Pod that mounts and uses the created ConfigMap
|
||||
* Verify that the configuration was correctly applied.
|
||||
-->
|
||||
|
||||
* 使用 Redis 配置的值创建一个 ConfigMap
|
||||
* 创建一个 Redis Pod,挂载并使用创建的 ConfigMap
|
||||
* 验证配置已经被正确应用
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
<!--
|
||||
* The example shown on this page works with `kubectl` 1.14 and above.
|
||||
* Understand [Configure a Pod to Use a ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/).
|
||||
-->
|
||||
* 此页面上显示的示例适用于 `kubectl` 1.14 及以上的版本。
|
||||
* 理解[配置 Pod 以使用 ConfigMap](/zh/docs/tasks/configure-pod-container/configure-pod-configmap/)。
|
||||
|
||||
|
||||
|
||||
<!-- lessoncontent -->
|
||||
|
||||
|
||||
<!--
|
||||
## Real World Example: Configuring Redis using a ConfigMap
|
||||
|
||||
Follow the steps below to configure a Redis cache using data stored in a ConfigMap.
|
||||
|
||||
First create a ConfigMap with an empty configuration block:
|
||||
-->
|
||||
## 真实世界的案例:使用 ConfigMap 来配置 Redis {#real-world-example-configuring-redis-using-a-configmap}
|
||||
|
||||
按照下面的步骤,使用 ConfigMap 中的数据来配置 Redis 缓存。
|
||||
|
||||
首先创建一个配置模块为空的 ConfigMap:
|
||||
|
||||
```shell
|
||||
cat <<EOF >./example-redis-config.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: example-redis-config
|
||||
data:
|
||||
redis-config: ""
|
||||
EOF
|
||||
```
|
||||
|
||||
<!--
|
||||
Apply the ConfigMap created above, along with a Redis pod manifest:
|
||||
-->
|
||||
应用上面创建的 ConfigMap 以及 Redis pod 清单:
|
||||
|
||||
```shell
|
||||
kubectl apply -f example-redis-config.yaml
|
||||
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
Examine the contents of the Redis pod manifest and note the following:
|
||||
|
||||
* A volume named `config` is created by `spec.volumes[1]`
|
||||
* The `key` and `path` under `spec.volumes[1].items[0]` exposes the `redis-config` key from the
|
||||
`example-redis-config` ConfigMap as a file named `redis.conf` on the `config` volume.
|
||||
* The `config` volume is then mounted at `/redis-master` by `spec.containers[0].volumeMounts[1]`.
|
||||
|
||||
This has the net effect of exposing the data in `data.redis-config` from the `example-redis-config`
|
||||
ConfigMap above as `/redis-master/redis.conf` inside the Pod.
|
||||
-->
|
||||
检查 Redis pod 清单的内容,并注意以下几点:
|
||||
|
||||
* 由 `spec.volumes[1]` 创建一个名为 `config` 的卷。
|
||||
* `spec.volumes[1].items[0]` 下的 `key` 和 `path` 会将来自 `example-redis-config`
|
||||
ConfigMap 中的 `redis-config` 密钥公开在 `config` 卷上一个名为 `redis-config` 的文件中。
|
||||
* 然后 `config` 卷被 `spec.containers[0].volumeMounts[1]` 挂载在 `/redis-master`。
|
||||
|
||||
这样做的最终效果是将上面 `example-redis-config` 配置中 `data.redis-config`
|
||||
的数据作为 Pod 中的 `/redis-master/redis.conf` 公开。
|
||||
|
||||
{{< codenew file="pods/config/redis-pod.yaml" >}}
|
||||
|
||||
<!--
|
||||
Examine the created objects:
|
||||
-->
|
||||
检查创建的对象:
|
||||
|
||||
```shell
|
||||
kubectl get pod/redis configmap/example-redis-config
|
||||
```
|
||||
|
||||
<!--
|
||||
You should see the following output:
|
||||
-->
|
||||
你应该可以看到以下输出:
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
pod/redis 1/1 Running 0 8s
|
||||
|
||||
NAME DATA AGE
|
||||
configmap/example-redis-config 1 14s
|
||||
```
|
||||
|
||||
<!--
|
||||
Recall that we left `redis-config` key in the `example-redis-config` ConfigMap blank:
|
||||
-->
|
||||
回顾一下,我们在 `example-redis-config` ConfigMap 保留了空的 `redis-config` 键:
|
||||
|
||||
```shell
|
||||
kubectl describe configmap/example-redis-config
|
||||
```
|
||||
|
||||
<!--
|
||||
You should see an empty `redis-config` key:
|
||||
-->
|
||||
你应该可以看到一个空的 `redis-config` 键:
|
||||
|
||||
```shell
|
||||
Name: example-redis-config
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Data
|
||||
====
|
||||
redis-config:
|
||||
```
|
||||
|
||||
<!--
|
||||
Use `kubectl exec` to enter the pod and run the `redis-cli` tool to check the current configuration:
|
||||
-->
|
||||
使用 `kubectl exec` 进入 pod,运行 `redis-cli` 工具检查当前配置:
|
||||
|
||||
```shell
|
||||
kubectl exec -it redis -- redis-cli
|
||||
```
|
||||
|
||||
<!--
|
||||
Check `maxmemory`:
|
||||
-->
|
||||
查看 `maxmemory`:
|
||||
|
||||
```shell
|
||||
127.0.0.1:6379> CONFIG GET maxmemory
|
||||
```
|
||||
|
||||
<!--
|
||||
It should show the default value of 0:
|
||||
-->
|
||||
它应该显示默认值 0:
|
||||
|
||||
```shell
|
||||
1) "maxmemory"
|
||||
2) "0"
|
||||
```
|
||||
|
||||
<!--
|
||||
Similarly, check `maxmemory-policy`:
|
||||
-->
|
||||
同样,查看 `maxmemory-policy`:
|
||||
|
||||
```shell
|
||||
127.0.0.1:6379> CONFIG GET maxmemory-policy
|
||||
```
|
||||
|
||||
<!--
|
||||
Which should also yield its default value of `noeviction`:
|
||||
-->
|
||||
它也应该显示默认值 `noeviction`:
|
||||
|
||||
```shell
|
||||
1) "maxmemory-policy"
|
||||
2) "noeviction"
|
||||
```
|
||||
|
||||
<!--
|
||||
Now let's add some configuration values to the `example-redis-config` ConfigMap:
|
||||
-->
|
||||
现在,向 `example-redis-config` ConfigMap 添加一些配置:
|
||||
|
||||
{{< codenew file="pods/config/example-redis-config.yaml" >}}
|
||||
|
||||
<!--
|
||||
Apply the updated ConfigMap:
|
||||
-->
|
||||
应用更新的 ConfigMap:
|
||||
|
||||
```shell
|
||||
kubectl apply -f example-redis-config.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
Confirm that the ConfigMap was updated:
|
||||
-->
|
||||
确认 ConfigMap 已更新:
|
||||
|
||||
```shell
|
||||
kubectl describe configmap/example-redis-config
|
||||
```
|
||||
|
||||
<!--
|
||||
You should see the configuration values we just added:
|
||||
-->
|
||||
你应该可以看到我们刚刚添加的配置:
|
||||
|
||||
```shell
|
||||
Name: example-redis-config
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Data
|
||||
====
|
||||
redis-config:
|
||||
----
|
||||
maxmemory 2mb
|
||||
maxmemory-policy allkeys-lru
|
||||
```
|
||||
|
||||
<!--
|
||||
Check the Redis Pod again using `redis-cli` via `kubectl exec` to see if the configuration was applied:
|
||||
-->
|
||||
通过 `kubectl exec` 使用 `redis-cli` 再次检查 Redis Pod,查看是否已应用配置:
|
||||
|
||||
```shell
|
||||
kubectl exec -it redis -- redis-cli
|
||||
```
|
||||
|
||||
<!--
|
||||
Check `maxmemory`:
|
||||
-->
|
||||
查看 `maxmemory`:
|
||||
|
||||
```shell
|
||||
127.0.0.1:6379> CONFIG GET maxmemory
|
||||
```
|
||||
|
||||
<!--
|
||||
It remains at the default value of 0:
|
||||
-->
|
||||
它保持默认值 0:
|
||||
|
||||
```shell
|
||||
1) "maxmemory"
|
||||
2) "0"
|
||||
```
|
||||
|
||||
<!--
|
||||
Similarly, `maxmemory-policy` remains at the `noeviction` default setting:
|
||||
-->
|
||||
同样,`maxmemory-policy` 保留为默认设置 `noeviction`:
|
||||
|
||||
```shell
|
||||
127.0.0.1:6379> CONFIG GET maxmemory-policy
|
||||
```
|
||||
|
||||
<!--
|
||||
Returns:
|
||||
-->
|
||||
返回:
|
||||
|
||||
```shell
|
||||
1) "maxmemory-policy"
|
||||
2) "noeviction"
|
||||
```
|
||||
|
||||
<!--
|
||||
The configuration values have not changed because the Pod needs to be restarted to grab updated
|
||||
values from associated ConfigMaps. Let's delete and recreate the Pod:
|
||||
-->
|
||||
配置值未更改,因为需要重新启动 Pod 才能从关联的 ConfigMap 中获取更新的值。
|
||||
让我们删除并重新创建 Pod:
|
||||
|
||||
```shell
|
||||
kubectl delete pod redis
|
||||
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
Now re-check the configuration values one last time:
|
||||
-->
|
||||
现在,最后一次重新检查配置值:
|
||||
|
||||
```shell
|
||||
kubectl exec -it redis -- redis-cli
|
||||
```
|
||||
|
||||
<!--
|
||||
Check `maxmemory`:
|
||||
-->
|
||||
查看 `maxmemory`:
|
||||
|
||||
```shell
|
||||
127.0.0.1:6379> CONFIG GET maxmemory
|
||||
```
|
||||
|
||||
<!--
|
||||
It should now return the updated value of 2097152:
|
||||
-->
|
||||
现在,它应该返回更新后的值 2097152:
|
||||
|
||||
```shell
|
||||
1) "maxmemory"
|
||||
2) "2097152"
|
||||
```
|
||||
|
||||
<!--
|
||||
Similarly, `maxmemory-policy` has also been updated:
|
||||
-->
|
||||
同样,`maxmemory-policy` 也已更新:
|
||||
|
||||
```shell
|
||||
127.0.0.1:6379> CONFIG GET maxmemory-policy
|
||||
```
|
||||
|
||||
<!--
|
||||
It now reflects the desired value of `allkeys-lru`:
|
||||
-->
|
||||
现在它反映了期望值 `allkeys-lru`:
|
||||
|
||||
```shell
|
||||
1) "maxmemory-policy"
|
||||
2) "allkeys-lru"
|
||||
```
|
||||
|
||||
<!--
|
||||
Clean up your work by deleting the created resources:
|
||||
-->
|
||||
删除创建的资源,清理你的工作:
|
||||
|
||||
```shell
|
||||
kubectl delete pod/redis configmap/example-redis-config
|
||||
```
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
|
||||
<!--
|
||||
* Learn more about [ConfigMaps](/docs/tasks/configure-pod-container/configure-pod-configmap/).
|
||||
-->
|
||||
* 了解有关 [ConfigMaps](/zh/docs/tasks/configure-pod-container/configure-pod-configmap/) 的更多信息。
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user