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: 50
|
||||
---
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,444 @@
|
||||
---
|
||||
title: "示例:使用 StatefulSet 部署 Cassandra"
|
||||
content_type: tutorial
|
||||
weight: 30
|
||||
---
|
||||
|
||||
<!--
|
||||
title: "Example: Deploying Cassandra with a StatefulSet"
|
||||
reviewers:
|
||||
- ahmetb
|
||||
content_type: tutorial
|
||||
weight: 30
|
||||
-->
|
||||
|
||||
<!-- overview -->
|
||||
<!--
|
||||
This tutorial shows you how to run [Apache Cassandra](https://cassandra.apache.org/) on Kubernetes.
|
||||
Cassandra, a database, needs persistent storage to provide data durability (application _state_).
|
||||
In this example, a custom Cassandra seed provider lets the database discover new Cassandra instances as they join the Cassandra cluster.
|
||||
-->
|
||||
本教程描述拉如何在 Kubernetes 上运行 [Apache Cassandra](https://cassandra.apache.org/)。
|
||||
数据库 Cassandra 需要永久性存储提供数据持久性(应用“状态”)。
|
||||
在此示例中,自定义 Cassandra seed provider 使数据库在加入 Cassandra
|
||||
集群时发现新的 Cassandra 实例。
|
||||
|
||||
<!--
|
||||
*StatefulSets* make it easier to deploy stateful applications into your Kubernetes cluster.
|
||||
For more information on the features used in this tutorial, see
|
||||
[StatefulSet](/docs/concepts/workloads/controllers/statefulset/).
|
||||
-->
|
||||
使用"StatefulSets"可以更轻松地将有状态的应用程序部署到你的 Kubernetes 集群中。
|
||||
有关本教程中使用的功能的更多信息,
|
||||
参阅 [StatefulSet](/zh/docs/concepts/workloads/controllers/statefulset/)。
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
Cassandra and Kubernetes both use the term _node_ to mean a member of a cluster. In this
|
||||
tutorial, the Pods that belong to the StatefulSet are Cassandra nodes and are members
|
||||
of the Cassandra cluster (called a _ring_). When those Pods run in your Kubernetes cluster,
|
||||
the Kubernetes control plane schedules those Pods onto Kubernetes
|
||||
{{< glossary_tooltip text="Nodes" term_id="node" >}}.
|
||||
-->
|
||||
Cassandra 和 Kubernetes 都使用术语“节点(node)”来表示集群的成员。
|
||||
在本教程中,属于 StatefulSet 的 Pod 是 Cassandra 节点,并且是 Cassandra 集群的成员(称为 “ring”)。
|
||||
当这些 Pod 在你的 Kubernetes 集群中运行时,Kubernetes 控制平面会将这些 Pod 调度到 Kubernetes 的
|
||||
{{< glossary_tooltip text="节点" term_id="node" >}}上。
|
||||
|
||||
<!--
|
||||
When a Cassandra node starts, it uses a _seed list_ to bootstrap discovery of other
|
||||
nodes in the ring.
|
||||
This tutorial deploys a custom Cassandra seed provider that lets the database discover
|
||||
new Cassandra Pods as they appear inside your Kubernetes cluster.
|
||||
-->
|
||||
当 Cassandra 节点启动时,使用 _seed列表_ 来引导发现 ring 中其他节点。
|
||||
本教程部署了一个自定义的 Cassandra seed provider,使数据库可以发现新的 Cassandra Pod
|
||||
出现在 Kubernetes 集群中。
|
||||
{{< /note >}}
|
||||
|
||||
## {{% heading "objectives" %}}
|
||||
|
||||
<!--
|
||||
* Create and validate a Cassandra headless {{< glossary_tooltip text="Service" term_id="service" >}}.
|
||||
* Use a {{< glossary_tooltip term_id="StatefulSet" >}} to create a Cassandra ring.
|
||||
* Validate the StatefulSet.
|
||||
* Modify the StatefulSet.
|
||||
* Delete the StatefulSet and its {{< glossary_tooltip text="Pods" term_id="pod" >}}.
|
||||
-->
|
||||
* 创建并验证 Cassandra 无头(headless){{< glossary_tooltip text="Service" term_id="service" >}}..
|
||||
* 使用 {{< glossary_tooltip term_id="StatefulSet" >}} 创建一个 Cassandra ring。
|
||||
* 验证 StatefulSet。
|
||||
* 修改 StatefulSet。
|
||||
* 删除 StatefulSet 及其 {{< glossary_tooltip text="Pod" term_id="pod" >}}.
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
<!--
|
||||
To complete this tutorial, you should already have a basic familiarity with
|
||||
{{< glossary_tooltip text="Pods" term_id="pod" >}},
|
||||
{{< glossary_tooltip text="Services" term_id="service" >}}, and
|
||||
{{< glossary_tooltip text="StatefulSets" term_id="StatefulSet" >}}.
|
||||
-->
|
||||
要完成本教程,你应该已经熟悉 {{< glossary_tooltip text="Pod" term_id="pod" >}},
|
||||
{{< glossary_tooltip text="Service" term_id="service" >}} 和
|
||||
{{< glossary_tooltip text="StatefulSet" term_id="StatefulSet" >}}。
|
||||
|
||||
<!--
|
||||
### Additional Minikube setup instructions
|
||||
|
||||
{{< caution >}}
|
||||
[Minikube](https://minikube.sigs.k8s.io/docs/) defaults to 2048MB of memory and 2 CPU.
|
||||
Running Minikube with the default resource configuration results in insufficient resource
|
||||
errors during this tutorial. To avoid these errors, start Minikube with the following settings:
|
||||
-->
|
||||
### 额外的 Minikube 设置说明
|
||||
|
||||
{{< caution >}}
|
||||
[Minikube](https://minikube.sigs.k8s.io/docs/)默认为 2048MB 内存和 2 个 CPU。
|
||||
在本教程中,使用默认资源配置运行 Minikube 会导致资源不足的错误。为避免这些错误,请使用以下设置启动 Minikube:
|
||||
|
||||
```shell
|
||||
minikube start --memory 5120 --cpus=4
|
||||
```
|
||||
{{< /caution >}}
|
||||
|
||||
|
||||
<!-- lessoncontent -->
|
||||
<!--
|
||||
## Creating a headless Service for Cassandra {#creating-a-cassandra-headless-service}
|
||||
|
||||
In Kubernetes, a {{< glossary_tooltip text="Service" term_id="service" >}} describes a set of
|
||||
{{< glossary_tooltip text="Pods" term_id="pod" >}} that perform the same task.
|
||||
|
||||
The following Service is used for DNS lookups between Cassandra Pods and clients within your cluster:
|
||||
|
||||
Create a Service to track all Cassandra StatefulSet members from the `cassandra-service.yaml` file:
|
||||
-->
|
||||
## 为 Cassandra 创建无头(headless) Services {#creating-a-cassandra-headless-service}
|
||||
|
||||
在 Kubernetes 中,一个 {{< glossary_tooltip text="Service" term_id="service" >}}
|
||||
描述了一组执行相同任务的 {{< glossary_tooltip text="Pod" term_id="pod" >}}。
|
||||
|
||||
以下 Service 用于在 Cassandra Pod 和集群中的客户端之间进行 DNS 查找:
|
||||
|
||||
{{< codenew file="application/cassandra/cassandra-service.yaml" >}}
|
||||
|
||||
创建一个 Service 来跟踪 `cassandra-service.yaml` 文件中的所有 Cassandra StatefulSet:
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/application/cassandra/cassandra-service.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
### Validating (optional) {#validating}
|
||||
|
||||
Get the Cassandra Service.
|
||||
-->
|
||||
### 验证(可选) {#validating}
|
||||
|
||||
获取 Cassandra Service。
|
||||
|
||||
```shell
|
||||
kubectl get svc cassandra
|
||||
```
|
||||
|
||||
<!--
|
||||
The response is
|
||||
-->
|
||||
响应是:
|
||||
|
||||
```
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
cassandra ClusterIP None <none> 9042/TCP 45s
|
||||
```
|
||||
|
||||
<!--
|
||||
If you don't see a Service named `cassandra`, that means creation failed. Read
|
||||
[Debug Services](/docs/tasks/debug/debug-application/debug-service/)
|
||||
for help troubleshooting common issues.
|
||||
-->
|
||||
如果没有看到名为 `cassandra` 的服务,则表示创建失败。
|
||||
请阅读[调试服务](/zh/docs/tasks/debug/debug-application/debug-service/),以解决常见问题。
|
||||
|
||||
<!--
|
||||
## Using a StatefulSet to create a Cassandra ring
|
||||
|
||||
The StatefulSet manifest, included below, creates a Cassandra ring that consists of three Pods.
|
||||
|
||||
{{< note >}}
|
||||
This example uses the default provisioner for Minikube.
|
||||
Please update the following StatefulSet for the cloud you are working with.
|
||||
{{< /note >}}
|
||||
-->
|
||||
## 使用 StatefulSet 创建 Cassandra Ring
|
||||
|
||||
下面包含的 StatefulSet 清单创建了一个由三个 Pod 组成的 Cassandra ring。
|
||||
|
||||
{{< note >}}
|
||||
本示例使用 Minikube 的默认配置程序。
|
||||
请为正在使用的云更新以下 StatefulSet。
|
||||
{{< /note >}}
|
||||
|
||||
{{< codenew file="application/cassandra/cassandra-statefulset.yaml" >}}
|
||||
|
||||
<!--
|
||||
Create the Cassandra StatefulSet from the `cassandra-statefulset.yaml` file:
|
||||
-->
|
||||
使用 `cassandra-statefulset.yaml` 文件创建 Cassandra StatefulSet :
|
||||
|
||||
```shell
|
||||
# 如果你能未经修改地 apply cassandra-statefulset.yaml,请使用此命令
|
||||
kubectl apply -f https://k8s.io/examples/application/cassandra/cassandra-statefulset.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
If you need to modify `cassandra-statefulset.yaml` to suit your cluster, download
|
||||
https://k8s.io/examples/application/cassandra/cassandra-statefulset.yaml and then apply
|
||||
that manifest, from the folder you saved the modified version into:
|
||||
-->
|
||||
如果你为了适合你的集群需要修改 `cassandra-statefulset.yaml`,
|
||||
下载 https://k8s.io/examples/application/cassandra/cassandra-statefulset.yaml,
|
||||
然后 apply 修改后的清单。
|
||||
|
||||
```shell
|
||||
# 如果使用本地的 cassandra-statefulset.yaml ,请使用此命令
|
||||
kubectl apply -f cassandra-statefulset.yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
## Validating the Cassandra StatefulSet
|
||||
|
||||
1. Get the Cassandra StatefulSet:
|
||||
-->
|
||||
## 验证 Cassandra StatefulSet
|
||||
|
||||
1. 获取 Cassandra StatefulSet:
|
||||
|
||||
```shell
|
||||
kubectl get statefulset cassandra
|
||||
```
|
||||
|
||||
<!--
|
||||
The response should be similar to:
|
||||
-->
|
||||
响应应该与此类似:
|
||||
|
||||
```
|
||||
NAME DESIRED CURRENT AGE
|
||||
cassandra 3 0 13s
|
||||
```
|
||||
|
||||
<!--
|
||||
The `StatefulSet` resource deploys Pods sequentially.
|
||||
-->
|
||||
`StatefulSet` 资源会按顺序部署 Pod。
|
||||
|
||||
<!--
|
||||
1. Get the Pods to see the ordered creation status:
|
||||
-->
|
||||
2. 获取 Pod 查看已排序的创建状态:
|
||||
|
||||
```shell
|
||||
kubectl get pods -l="app=cassandra"
|
||||
```
|
||||
|
||||
<!--
|
||||
The response should be similar to:
|
||||
-->
|
||||
响应应该与此类似:
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
cassandra-0 1/1 Running 0 1m
|
||||
cassandra-1 0/1 ContainerCreating 0 8s
|
||||
```
|
||||
|
||||
<!--
|
||||
It can take several minutes for all three Pods to deploy. Once they are deployed, the same command
|
||||
returns output similar to:
|
||||
-->
|
||||
这三个 Pod 要花几分钟的时间才能部署。部署之后,相同的命令将返回类似于以下的输出:
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
cassandra-0 1/1 Running 0 10m
|
||||
cassandra-1 1/1 Running 0 9m
|
||||
cassandra-2 1/1 Running 0 8m
|
||||
```
|
||||
<!--
|
||||
3. Run the Cassandra [nodetool](https://cwiki.apache.org/confluence/display/CASSANDRA2/NodeTool) inside the first Pod, to
|
||||
display the status of the ring.
|
||||
-->
|
||||
3. 运行第一个 Pod 中的 Cassandra [nodetool](https://cwiki.apache.org/confluence/display/CASSANDRA2/NodeTool),
|
||||
以显示 ring 的状态。
|
||||
|
||||
```shell
|
||||
kubectl exec -it cassandra-0 -- nodetool status
|
||||
```
|
||||
|
||||
<!--
|
||||
The response should be similar to:
|
||||
-->
|
||||
响应应该与此类似:
|
||||
|
||||
```
|
||||
Datacenter: DC1-K8Demo
|
||||
======================
|
||||
Status=Up/Down
|
||||
|/ State=Normal/Leaving/Joining/Moving
|
||||
-- Address Load Tokens Owns (effective) Host ID Rack
|
||||
UN 172.17.0.5 83.57 KiB 32 74.0% e2dd09e6-d9d3-477e-96c5-45094c08db0f Rack1-K8Demo
|
||||
UN 172.17.0.4 101.04 KiB 32 58.8% f89d6835-3a42-4419-92b3-0e62cae1479c Rack1-K8Demo
|
||||
UN 172.17.0.6 84.74 KiB 32 67.1% a6a1e8c2-3dc5-4417-b1a0-26507af2aaad Rack1-K8Demo
|
||||
```
|
||||
|
||||
<!--
|
||||
## Modifying the Cassandra StatefulSet
|
||||
|
||||
Use `kubectl edit` to modify the size of a Cassandra StatefulSet.
|
||||
|
||||
1. Run the following command:
|
||||
-->
|
||||
## 修改 Cassandra StatefulSet
|
||||
|
||||
使用 `kubectl edit` 修改 Cassandra StatefulSet 的大小。
|
||||
|
||||
1. 运行以下命令:
|
||||
|
||||
```shell
|
||||
kubectl edit statefulset cassandra
|
||||
```
|
||||
|
||||
<!--
|
||||
This command opens an editor in your terminal. The line you need to change is the `replicas` field.
|
||||
The following sample is an excerpt of the StatefulSet file:
|
||||
-->
|
||||
此命令你的终端中打开一个编辑器。需要更改的是 `replicas` 字段。下面是 StatefulSet 文件的片段示例:
|
||||
|
||||
```yaml
|
||||
# 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: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
creationTimestamp: 2016-08-13T18:40:58Z
|
||||
generation: 1
|
||||
labels:
|
||||
app: cassandra
|
||||
name: cassandra
|
||||
namespace: default
|
||||
resourceVersion: "323"
|
||||
uid: 7a219483-6185-11e6-a910-42010a8a0fc0
|
||||
spec:
|
||||
replicas: 3
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Change the number of replicas to 4, and then save the manifest.
|
||||
|
||||
The StatefulSet now scales to run with 4 Pods.
|
||||
|
||||
1. Get the Cassandra StatefulSet to verify your change:
|
||||
-->
|
||||
2. 将副本数(replicas)更改为 4,然后保存清单。
|
||||
|
||||
StatefulSet 现在可以扩展到运行 4 个 Pod。
|
||||
|
||||
3. 获取 Cassandra StatefulSet 验证更改:
|
||||
|
||||
```shell
|
||||
kubectl get statefulset cassandra
|
||||
```
|
||||
|
||||
<!--
|
||||
The response should be similar to:
|
||||
-->
|
||||
响应应该与此类似:
|
||||
|
||||
```
|
||||
NAME DESIRED CURRENT AGE
|
||||
cassandra 4 4 36m
|
||||
```
|
||||
|
||||
## {{% heading "cleanup" %}}
|
||||
|
||||
<!--
|
||||
Deleting or scaling a StatefulSet down does not delete the volumes associated with the StatefulSet.
|
||||
This setting is for your safety because your data is more valuable than automatically purging all related StatefulSet resources.
|
||||
-->
|
||||
删除或缩小 StatefulSet 不会删除与 StatefulSet 关联的卷。
|
||||
这个设置是出于安全考虑,因为你的数据比自动清除所有相关的 StatefulSet 资源更有价值。
|
||||
|
||||
{{< warning >}}
|
||||
<!--
|
||||
Depending on the storage class and reclaim policy, deleting the *PersistentVolumeClaims* may cause the associated volumes
|
||||
to also be deleted. Never assume you'll be able to access data if its volume claims are deleted.
|
||||
-->
|
||||
根据存储类和回收策略,删除 *PersistentVolumeClaims* 可能导致关联的卷也被删除。
|
||||
千万不要认为其容量声明被删除,你就能访问数据。
|
||||
{{< /warning >}}
|
||||
|
||||
<!--
|
||||
1. Run the following commands (chained together into a single command) to delete everything in the Cassandra StatefulSet:
|
||||
-->
|
||||
1. 运行以下命令(连在一起成为一个单独的命令)删除 Cassandra StatefulSet 中的所有内容:
|
||||
|
||||
```shell
|
||||
grace=$(kubectl get pod cassandra-0 -o=jsonpath='{.spec.terminationGracePeriodSeconds}') \
|
||||
&& kubectl delete statefulset -l app=cassandra \
|
||||
&& echo "Sleeping ${grace} seconds" 1>&2 \
|
||||
&& sleep $grace \
|
||||
&& kubectl delete persistentvolumeclaim -l app=cassandra
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Run the following command to delete the Service you set up for Cassandra:
|
||||
-->
|
||||
2. 运行以下命令,删除你为 Cassandra 设置的 Service:
|
||||
|
||||
```shell
|
||||
kubectl delete service -l app=cassandra
|
||||
```
|
||||
|
||||
<!--
|
||||
## Cassandra container environment variables
|
||||
|
||||
The Pods in this tutorial use the [`gcr.io/google-samples/cassandra:v13`](https://github.com/kubernetes/examples/blob/master/cassandra/image/Dockerfile)
|
||||
image from Google's [container registry](https://cloud.google.com/container-registry/docs/).
|
||||
The Docker image above is based on [debian-base](https://github.com/kubernetes/release/tree/master/images/build/debian-base)
|
||||
and includes OpenJDK 8.
|
||||
|
||||
This image includes a standard Cassandra installation from the Apache Debian repo.
|
||||
By using environment variables you can change values that are inserted into `cassandra.yaml`.
|
||||
-->
|
||||
## Cassandra 容器环境变量
|
||||
|
||||
本教程中的 Pod 使用来自 Google [容器镜像库](https://cloud.google.com/container-registry/docs/)
|
||||
的 [`gcr.io/google-samples/cassandra:v13`](https://github.com/kubernetes/examples/blob/master/cassandra/image/Dockerfile)
|
||||
镜像。上面的 Docker 镜像基于 [debian-base](https://github.com/kubernetes/release/tree/master/images/build/debian-base),
|
||||
并且包含 OpenJDK 8。
|
||||
|
||||
该映像包括来自 Apache Debian 存储库的标准 Cassandra 安装。
|
||||
通过使用环境变量,你可以更改插入到 `cassandra.yaml` 中的值。
|
||||
|
||||
| 环境变量 | 默认值 |
|
||||
| ------------------------ |:---------------: |
|
||||
| `CASSANDRA_CLUSTER_NAME` | `'Test Cluster'` |
|
||||
| `CASSANDRA_NUM_TOKENS` | `32` |
|
||||
| `CASSANDRA_RPC_ADDRESS` | `0.0.0.0` |
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
<!--
|
||||
* Learn how to [Scale a StatefulSet](/docs/tasks/run-application/scale-stateful-set/).
|
||||
* Learn more about the [*KubernetesSeedProvider*](https://github.com/kubernetes/examples/blob/master/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java)
|
||||
* See more custom [Seed Provider Configurations](https://git.k8s.io/examples/cassandra/java/README.md)
|
||||
-->
|
||||
* 了解如何[扩缩 StatefulSet](/docs/tasks/run-application/scale-stateful-set/)。
|
||||
* 了解有关 [*KubernetesSeedProvider*](https://github.com/kubernetes/examples/blob/master/cassandra/java/src/main/java/io/k8s/cassandra/KubernetesSeedProvider.java) 的更多信息
|
||||
* 查看更多自定义 [Seed Provider Configurations](https://git.k8s.io/examples/cassandra/java/README.md)
|
||||
|
||||
+461
@@ -0,0 +1,461 @@
|
||||
---
|
||||
title: 示例:使用 Persistent Volumes 部署 WordPress 和 MySQL
|
||||
content_type: tutorial
|
||||
weight: 20
|
||||
card:
|
||||
name: tutorials
|
||||
weight: 40
|
||||
title: "有状态应用示例: 带持久卷的 Wordpress"
|
||||
---
|
||||
<!--
|
||||
title: "Example: Deploying WordPress and MySQL with Persistent Volumes"
|
||||
reviewers:
|
||||
- ahmetb
|
||||
content_type: tutorial
|
||||
weight: 20
|
||||
card:
|
||||
name: tutorials
|
||||
weight: 40
|
||||
title: "Stateful Example: Wordpress with Persistent Volumes"
|
||||
-->
|
||||
<!-- overview -->
|
||||
|
||||
<!--
|
||||
This tutorial shows you how to deploy a WordPress site and a MySQL database using Minikube. Both applications use PersistentVolumes and PersistentVolumeClaims to store data.
|
||||
-->
|
||||
本示例描述了如何通过 Minikube 在 Kubernetes 上安装 WordPress 和 MySQL。
|
||||
这两个应用都使用 PersistentVolumes 和 PersistentVolumeClaims 保存数据。
|
||||
|
||||
<!--
|
||||
A [PersistentVolume](/docs/concepts/storage/persistent-volumes/)(PV)is a piece of storage in the cluster that has been manually provisioned by an administrator, or dynamically provisioned by Kubernetes using a [StorageClass](/docs/concepts/storage/storage-classes). A [PersistentVolumeClaim](/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims)(PVC)is a request for storage by a user that can be fulfilled by a PV. PersistentVolumes and PersistentVolumeClaims are independent from Pod lifecycles and preserve data through restarting, rescheduling, and even deleting Pods.
|
||||
-->
|
||||
[PersistentVolume](/zh/docs/concepts/storage/persistent-volumes/)(PV)是一块集群里由管理员手动提供,
|
||||
或 kubernetes 通过 [StorageClass](/zh/docs/concepts/storage/storage-classes) 动态创建的存储。
|
||||
[PersistentVolumeClaim](/zh/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims)
|
||||
是用户对存储的请求,该请求可由某个 PV 来满足。
|
||||
PersistentVolumes 和 PersistentVolumeClaims 独立于 Pod 生命周期而存在,
|
||||
在 Pod 重启,重新调度甚至删除过程中保存数据。
|
||||
|
||||
{{< warning >}}
|
||||
<!--
|
||||
This deployment is not suitable for production use cases, as it uses single instance WordPress and MySQL Pods. Consider using [WordPress Helm Chart](https://github.com/kubernetes/charts/tree/master/stable/wordpress) to deploy WordPress in production.
|
||||
-->
|
||||
这种部署并不适合生产场景,它使用单实例 WordPress 和 MySQL Pods。
|
||||
在生产场景中,请考虑使用 [WordPress Helm Chart](https://github.com/kubernetes/charts/tree/master/stable/wordpress)
|
||||
部署 WordPress。
|
||||
{{< /warning >}}
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
The files provided in this tutorial are using GA Deployment APIs and are specific to kubernetes version 1.9 and later. If you wish to use this tutorial with an earlier version of Kubernetes, please update the API version appropriately, or reference earlier versions of this tutorial.
|
||||
-->
|
||||
本教程中提供的文件使用 GA Deployment API,并且特定于 kubernetes 1.9 或更高版本。如果你希望将本教程与 Kubernetes 的早期版本一起使用,请相应地更新 API 版本,或参考本教程的早期版本。
|
||||
{{< /note >}}
|
||||
|
||||
## {{% heading "objectives" %}}
|
||||
|
||||
<!--
|
||||
* Create PersistentVolumeClaims and PersistentVolumes
|
||||
* Create a `kustomization.yaml` with
|
||||
* a Secret generator
|
||||
* MySQL resource configs
|
||||
* WordPress resource configs
|
||||
* Apply the kustomization directory by `kubectl apply -k ./`
|
||||
* Clean up
|
||||
-->
|
||||
* 创建 PersistentVolumeClaims 和 PersistentVolumes
|
||||
* 创建 `kustomization.yaml` 使用
|
||||
* Secret 生成器
|
||||
* MySQL 资源配置
|
||||
* WordPress 资源配置
|
||||
* 应用整个 kustomization 目录 `kubectl apply -k ./`
|
||||
* 清理
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
|
||||
|
||||
<!--
|
||||
The example shown on this page works with `kubectl` 1.14 and above.
|
||||
|
||||
Download the following configuration files:
|
||||
|
||||
1. [mysql-deployment.yaml](/examples/application/wordpress/mysql-deployment.yaml)
|
||||
|
||||
1. [wordpress-deployment.yaml](/examples/application/wordpress/wordpress-deployment.yaml)
|
||||
-->
|
||||
此例在`kubectl` 1.14 或者更高版本有效。
|
||||
|
||||
下载下面的配置文件:
|
||||
|
||||
1. [mysql-deployment.yaml](/examples/application/wordpress/mysql-deployment.yaml)
|
||||
|
||||
2. [wordpress-deployment.yaml](/examples/application/wordpress/wordpress-deployment.yaml)
|
||||
|
||||
<!-- lessoncontent -->
|
||||
|
||||
<!--
|
||||
## Create PersistentVolumeClaims and PersistentVolumes
|
||||
-->
|
||||
## 创建 PersistentVolumeClaims 和 PersistentVolumes
|
||||
<!-- MySQL and Wordpress each require a PersistentVolume to store data. Their PersistentVolumeClaims will be created at the deployment step.
|
||||
|
||||
Many cluster environments have a default StorageClass installed. When a StorageClass is not specified in the PersistentVolumeClaim, the cluster's default StorageClass is used instead.
|
||||
|
||||
When a PersistentVolumeClaim is created, a PersistentVolume is dynamically provisioned based on the StorageClass configuration.
|
||||
-->
|
||||
|
||||
MySQL 和 Wordpress 都需要一个 PersistentVolume 来存储数据。
|
||||
他们的 PersistentVolumeClaims 将在部署步骤中创建。
|
||||
|
||||
许多集群环境都安装了默认的 StorageClass。如果在 PersistentVolumeClaim 中未指定 StorageClass,
|
||||
则使用集群的默认 StorageClass。
|
||||
|
||||
创建 PersistentVolumeClaim 时,将根据 StorageClass 配置动态设置 PersistentVolume。
|
||||
|
||||
{{< warning >}}
|
||||
<!--
|
||||
In local clusters, the default StorageClass uses the `hostPath` provisioner. `hostPath` volumes are only suitable for development and testing. With `hostPath` volumes, your data lives in `/tmp` on the node the Pod is scheduled onto and does not move between nodes. If a Pod dies and gets scheduled to another node in the cluster, or the node is rebooted, the data is lost.
|
||||
-->
|
||||
|
||||
在本地集群中,默认的 StorageClass 使用`hostPath`供应器。 `hostPath`卷仅适用于开发和测试。
|
||||
使用 `hostPath` 卷,你的数据位于 Pod 调度到的节点上的`/tmp`中,并且不会在节点之间移动。
|
||||
如果 Pod 死亡并被调度到集群中的另一个节点,或者该节点重新启动,则数据将丢失。
|
||||
{{< /warning >}}
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
If you are bringing up a cluster that needs to use the `hostPath` provisioner, the `--enable-hostpath-provisioner` flag must be set in the `controller-manager` component.
|
||||
-->
|
||||
如果要建立需要使用`hostPath`设置程序的集群,
|
||||
则必须在 controller-manager 组件中设置`--enable-hostpath-provisioner`标志。
|
||||
{{< /note >}}
|
||||
|
||||
{{< note >}}
|
||||
<!-- If you have a Kubernetes cluster running on Google Kubernetes Engine, please follow [this guide](https://cloud.google.com/kubernetes-engine/docs/tutorials/persistent-disk). -->
|
||||
|
||||
如果你已经有运行在 Google Kubernetes Engine 的集群,
|
||||
请参考[此指南](https://cloud.google.com/kubernetes-engine/docs/tutorials/persistent-disk)。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
## Create a kustomization.yaml
|
||||
-->
|
||||
## 创建 kustomization.yaml
|
||||
|
||||
<!--
|
||||
### Add a Secret generator
|
||||
-->
|
||||
### 创建 Secret 生成器
|
||||
|
||||
<!--
|
||||
A [Secret](/docs/concepts/configuration/secret/) is an object that stores a piece of sensitive data like a password or key. Since 1.14, `kubectl` supports the management of Kubernetes objects using a kustomization file. You can create a Secret by generators in `kustomization.yaml`.
|
||||
|
||||
Add a Secret generator in `kustomization.yaml` from the following command. You will need to replace `YOUR_PASSWORD` with the password you want to use.
|
||||
-->
|
||||
[Secret](/zh/docs/concepts/configuration/secret/) 是存储诸如密码或密钥之类的敏感数据的对象。
|
||||
从 1.14 开始,`kubectl`支持使用 kustomization 文件管理 Kubernetes 对象。
|
||||
你可以通过`kustomization.yaml`中的生成器创建一个 Secret。
|
||||
|
||||
通过以下命令在`kustomization.yaml`中添加一个 Secret 生成器。
|
||||
你需要用你要使用的密码替换`YOUR_PASSWORD`。
|
||||
|
||||
```shell
|
||||
cat <<EOF >./kustomization.yaml
|
||||
secretGenerator:
|
||||
- name: mysql-pass
|
||||
literals:
|
||||
- password=YOUR_PASSWORD
|
||||
EOF
|
||||
```
|
||||
|
||||
<!--
|
||||
## Add resource configs for MySQL and WordPress
|
||||
-->
|
||||
## 补充 MySQL 和 WordPress 的资源配置
|
||||
|
||||
<!--
|
||||
The following manifest describes a single-instance MySQL Deployment. The MySQL container mounts the PersistentVolume at /var/lib/mysql. The `MYSQL_ROOT_PASSWORD` environment variable sets the database password from the Secret.
|
||||
-->
|
||||
以下 manifest 文件描述了单实例 MySQL 部署。MySQL 容器将 PersistentVolume 挂载在`/var/lib/mysql`。
|
||||
`MYSQL_ROOT_PASSWORD`环境变量设置来自 Secret 的数据库密码。
|
||||
|
||||
{{< codenew file="application/wordpress/mysql-deployment.yaml" >}}
|
||||
|
||||
<!--
|
||||
The following manifest describes a single-instance WordPress Deployment. The WordPress container mounts the
|
||||
PersistentVolume at `/var/www/html` for website data files. The `WORDPRESS_DB_HOST` environment variable sets
|
||||
the name of the MySQL Service defined above, and WordPress will access the database by Service. The
|
||||
`WORDPRESS_DB_PASSWORD` environment variable sets the database password from the Secret kustomize generated.
|
||||
-->
|
||||
以下 manifest 文件描述了单实例 WordPress 部署。WordPress 容器将网站数据文件位于`/var/www/html`的 PersistentVolume。`WORDPRESS_DB_HOST`环境变量集上面定义的 MySQL Service 的名称,WordPress 将通过 Service 访问数据库。`WORDPRESS_DB_PASSWORD`环境变量设置从 Secret kustomize 生成的数据库密码。
|
||||
{{< codenew file="application/wordpress/wordpress-deployment.yaml" >}}
|
||||
|
||||
<!--
|
||||
1. Download the MySQL deployment configuration file.
|
||||
|
||||
```shell
|
||||
curl -LO https://k8s.io/examples/application/wordpress/mysql-deployment.yaml
|
||||
```
|
||||
|
||||
2. Download the WordPress configuration file.
|
||||
|
||||
```shell
|
||||
curl -LO https://k8s.io/examples/application/wordpress/wordpress-deployment.yaml
|
||||
```
|
||||
|
||||
3. Add them to `kustomization.yaml` file.
|
||||
|
||||
```shell
|
||||
cat <<EOF >>./kustomization.yaml
|
||||
resources:
|
||||
- mysql-deployment.yaml
|
||||
- wordpress-deployment.yaml
|
||||
EOF
|
||||
```
|
||||
-->
|
||||
1. 下载 MySQL deployment 配置文件。
|
||||
|
||||
```shell
|
||||
curl -LO https://k8s.io/examples/application/wordpress/mysql-deployment.yaml
|
||||
```
|
||||
|
||||
2. 下载 WordPress 配置文件。
|
||||
|
||||
```shell
|
||||
curl -LO https://k8s.io/examples/application/wordpress/wordpress-deployment.yaml
|
||||
```
|
||||
|
||||
3. 补充到 `kustomization.yaml` 文件。
|
||||
|
||||
```shell
|
||||
cat <<EOF >>./kustomization.yaml
|
||||
resources:
|
||||
- mysql-deployment.yaml
|
||||
- wordpress-deployment.yaml
|
||||
EOF
|
||||
```
|
||||
|
||||
<!--
|
||||
## Apply and Verify
|
||||
-->
|
||||
## 应用和验证
|
||||
|
||||
<!--
|
||||
The `kustomization.yaml` contains all the resources for deploying a WordPress site and a
|
||||
MySQL database. You can apply the directory by
|
||||
```shell
|
||||
kubectl apply -k ./
|
||||
```
|
||||
|
||||
Now you can verify that all objects exist.
|
||||
|
||||
1. Verify that the Secret exists by running the following command:
|
||||
|
||||
```shell
|
||||
kubectl get secrets
|
||||
```
|
||||
|
||||
The response should be like this:
|
||||
|
||||
```shell
|
||||
NAME TYPE DATA AGE
|
||||
mysql-pass-c57bb4t7mf Opaque 1 9s
|
||||
```
|
||||
|
||||
2. Verify that a PersistentVolume got dynamically provisioned.
|
||||
|
||||
```shell
|
||||
kubectl get pvc
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
It can take up to a few minutes for the PVs to be provisioned and bound.
|
||||
{{< /note >}}
|
||||
|
||||
The response should be like this:
|
||||
|
||||
```shell
|
||||
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
|
||||
mysql-pv-claim Bound pvc-8cbd7b2e-4044-11e9-b2bb-42010a800002 20Gi RWO standard 77s
|
||||
wp-pv-claim Bound pvc-8cd0df54-4044-11e9-b2bb-42010a800002 20Gi RWO standard 77s
|
||||
```
|
||||
|
||||
3. Verify that the Pod is running by running the following command:
|
||||
|
||||
```shell
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
It can take up to a few minutes for the Pod's Status to be `RUNNING`.
|
||||
{{< /note >}}
|
||||
|
||||
The response should be like this:
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
wordpress-mysql-1894417608-x5dzt 1/1 Running 0 40s
|
||||
```
|
||||
|
||||
4. Verify that the Service is running by running the following command:
|
||||
|
||||
```shell
|
||||
kubectl get services wordpress
|
||||
```
|
||||
|
||||
The response should be like this:
|
||||
|
||||
```
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
wordpress ClusterIP 10.0.0.89 <pending> 80:32406/TCP 4m
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
Minikube can only expose Services through `NodePort`. The EXTERNAL-IP is always pending.
|
||||
{{< /note >}}
|
||||
|
||||
5. Run the following command to get the IP Address for the WordPress Service:
|
||||
|
||||
```shell
|
||||
minikube service wordpress --url
|
||||
```
|
||||
|
||||
The response should be like this:
|
||||
|
||||
```
|
||||
http://1.2.3.4:32406
|
||||
```
|
||||
|
||||
6. Copy the IP address, and load the page in your browser to view your site.
|
||||
|
||||
You should see the WordPress set up page similar to the following screenshot.
|
||||
|
||||

|
||||
-->
|
||||
`kustomization.yaml`包含用于部署 WordPress 网站的所有资源以及 MySQL 数据库。你可以通过以下方式应用目录
|
||||
```shell
|
||||
kubectl apply -k ./
|
||||
```
|
||||
|
||||
现在,你可以验证所有对象是否存在。
|
||||
|
||||
1. 通过运行以下命令验证 Secret 是否存在:
|
||||
|
||||
```shell
|
||||
kubectl get secrets
|
||||
```
|
||||
|
||||
响应应如下所示:
|
||||
|
||||
```shell
|
||||
NAME TYPE DATA AGE
|
||||
mysql-pass-c57bb4t7mf Opaque 1 9s
|
||||
```
|
||||
|
||||
2. 验证是否已动态配置 PersistentVolume:
|
||||
|
||||
```shell
|
||||
kubectl get pvc
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
设置和绑定 PV 可能要花费几分钟。
|
||||
{{< /note >}}
|
||||
|
||||
响应应如下所示:
|
||||
|
||||
```shell
|
||||
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
|
||||
mysql-pv-claim Bound pvc-8cbd7b2e-4044-11e9-b2bb-42010a800002 20Gi RWO standard 77s
|
||||
wp-pv-claim Bound pvc-8cd0df54-4044-11e9-b2bb-42010a800002 20Gi RWO standard 77s
|
||||
```
|
||||
|
||||
3. 通过运行以下命令来验证 Pod 是否正在运行:
|
||||
|
||||
```shell
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
等待 Pod 状态变成`RUNNING`可能会花费几分钟。
|
||||
{{< /note >}}
|
||||
|
||||
响应应如下所示:
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
wordpress-mysql-1894417608-x5dzt 1/1 Running 0 40s
|
||||
```
|
||||
|
||||
4. 通过运行以下命令来验证 Service 是否正在运行:
|
||||
|
||||
```shell
|
||||
kubectl get services wordpress
|
||||
```
|
||||
|
||||
响应应如下所示:
|
||||
|
||||
```
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
wordpress ClusterIP 10.0.0.89 <pending> 80:32406/TCP 4m
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
Minikube 只能通过 NodePort 公开服务。EXTERNAL-IP 始终处于挂起状态
|
||||
{{< /note >}}
|
||||
|
||||
5. 运行以下命令以获取 WordPress 服务的 IP 地址:
|
||||
|
||||
```shell
|
||||
minikube service wordpress --url
|
||||
```
|
||||
|
||||
响应应如下所示:
|
||||
|
||||
```
|
||||
http://1.2.3.4:32406
|
||||
```
|
||||
|
||||
6. 复制 IP 地址,然后将页面加载到浏览器中来查看你的站点。
|
||||
|
||||
你应该看到类似于以下屏幕截图的 WordPress 设置页面。
|
||||
|
||||

|
||||
|
||||
{{< warning >}}
|
||||
<!--
|
||||
Do not leave your WordPress installation on this page. If another user finds it, they can set up a website on your instance and use it to serve malicious content. <br/><br/>Either install WordPress by creating a username and password or delete your instance.
|
||||
-->
|
||||
不要在此页面上保留 WordPress 安装。如果其他用户找到了它,他们可以在你的实例上建立一个网站并使用它来提供恶意内容。<br/><br/>通过创建用户名和密码来安装 WordPress 或删除你的实例。
|
||||
|
||||
{{< /warning >}}
|
||||
|
||||
## {{% heading "cleanup" %}}
|
||||
|
||||
<!--
|
||||
1. Run the following command to delete your Secret, Deployments, Services and PersistentVolumeClaims:
|
||||
|
||||
```shell
|
||||
kubectl delete -k ./
|
||||
```
|
||||
-->
|
||||
|
||||
1. 运行一下命令删除你的 Secret,Deployments,Services and PersistentVolumeClaims:
|
||||
|
||||
```shell
|
||||
kubectl delete -k ./
|
||||
```
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
<!--
|
||||
* Learn more about [Introspection and Debugging](/docs/tasks/debug/debug-application/debug-running-pod/)
|
||||
* Learn more about [Jobs](/docs/concepts/workloads/controllers/jobs-run-to-completion/)
|
||||
* Learn more about [Port Forwarding](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/)
|
||||
* Learn how to [Get a Shell to a Container](/docs/tasks/debug/debug-application/get-shell-running-container/)
|
||||
-->
|
||||
* 进一步了解[自省与调试](/zh/docs/tasks/debug/debug-application/debug-running-pod/)
|
||||
* 进一步了解 [Job](/zh/docs/concepts/workloads/controllers/jobs-run-to-completion/)
|
||||
* 进一步了解[端口转发](/zh/docs/tasks/access-application-cluster/port-forward-access-application-cluster/)
|
||||
* 了解如何[获得容器的 Shell](/zh/docs/tasks/debug/debug-application/get-shell-running-container/)
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user