[zh] Resync setup section (2)

This commit is contained in:
Qiming Teng
2021-04-26 16:14:23 +08:00
parent 1869573927
commit 544d3c2fb7
7 changed files with 595 additions and 744 deletions
@@ -19,9 +19,9 @@ It uses a tool called [`kops`](https://github.com/kubernetes/kops).
本篇使用了一个名为 [`kops`](https://github.com/kubernetes/kops) 的工具。
<!--
kops is an opinionated provisioning system:
kops is an automated provisioning system:
-->
kops 是一个自用的供应系统:
kops 是一个自动化的制备系统:
<!--
* Fully automated installation
@@ -33,80 +33,170 @@ kops 是一个自用的供应系统:
-->
* 全自动安装流程
* 使用 DNS 识别集群
* 自我修复:一切都在自动扩组中运行
* 自我修复:一切都在自动扩组中运行
* 支持多种操作系统(如 Debian、Ubuntu 16.04、CentOS、RHEL、Amazon Linux 和 CoreOS - 参考 [images.md](https://github.com/kubernetes/kops/blob/master/docs/operations/images.md)
* 支持高可用 - 参考 [high_availability.md](https://github.com/kubernetes/kops/blob/master/docs/high_availability.md)
* 可以直接提供或者生成 terraform 清单 - 参考 [terraform.md](https://github.com/kubernetes/kops/blob/master/docs/terraform.md)
<!--
If your opinions differ from these you may prefer to build your own cluster using [kubeadm](/docs/admin/kubeadm/) as
a building block. kops builds on the kubeadm work.
-->
如果你有不同的观点,你可能更喜欢使用 [kubeadm](/zh/docs/reference/setup-tools/kubeadm/)
作为构建工具来构建自己的集群。kops 建立在 kubeadm 工作的基础上。
## {{% heading "prerequisites" %}}
<!-- body -->
<!--
* You must have [kubectl](/docs/tasks/tools/) installed.
* You must [install](https://github.com/kubernetes/kops#installing) `kops` on a 64-bit (AMD64 and Intel 64) device architecture.
* You must have an [AWS account](https://docs.aws.amazon.com/polly/latest/dg/setting-up.html), generate [IAM keys](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) and [configure](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration) them. The IAM user will need [adequate permissions](https://github.com/kubernetes/kops/blob/master/docs/getting_started/aws.md#setup-iam-user).
-->
* 你必须安装 [kubectl](/zh/docs/tasks/tools/)。
* 你必须安装[安装](https://github.com/kubernetes/kops#installing) `kops`
到 64 位的(AMD64 和 Intel 64)设备架构上。
* 你必须拥有一个 [AWS 账户](https://docs.aws.amazon.com/polly/latest/dg/setting-up.html)
生成 [IAM 秘钥](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys)
并[配置](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration)
该秘钥。IAM 用户需要[足够的权限许可](https://github.com/kubernetes/kops/blob/master/docs/getting_started/aws.md#setup-iam-user)。
<!-- steps -->
<!--
## Creating a cluster
### (1/5) Install kops
#### Requirements
#### Installation
You must have [kubectl](/docs/tasks/tools/install-kubectl/) installed in order for kops to work.
Download kops from the [releases page](https://github.com/kubernetes/kops/releases) (it is also convenient to build from source):
-->
## 创建集群
### (1/5) 安装 kops
#### 前提条件
你必须安装 [kubectl](/zh/docs/tasks/tools/install-kubectl/) 才能使 kops 工作。
<!--
#### Installation
Download kops from the [releases page](https://github.com/kubernetes/kops/releases) (it is also easy to build from source):
-->
#### 安装
从[下载页面](https://github.com/kubernetes/kops/releases)下载 kops(从源代码构建也很容易):
从[下载页面](https://github.com/kubernetes/kops/releases)下载 kops
(从源代码构建也很方便):
{{< tabs name="kops_installation" >}}
{{% tab name="macOS" %}}
<!--
On macOS:
# you can also install using Homebrew
Download the latest release with the command:
-->
在 macOS 上
使用下面的命令下载最新发布版本
```shell
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-darwin-amd64
```
<!--
To download a specific version, replace the following portion of the command with the specific kops version.
-->
要下载特定版本,使用特定的 kops 版本替换下面命令中的部分:
```shell
$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)
```
<!--
For example, to download kops version v1.20.0 type:
-->
例如,要下载 kops v1.20.0,输入:
```shell
curl -LO https://github.com/kubernetes/kops/releases/download/v1.20.0/kops-darwin-amd64
```
<!--
Make the kops binary executable.
-->
令 kops 二进制文件可执行:
```shell
curl -OL https://github.com/kubernetes/kops/releases/download/1.10.0/kops-darwin-amd64
chmod +x kops-darwin-amd64
mv kops-darwin-amd64 /usr/local/bin/kops
# 你也可以使用 Homebrew 安装 kops
```
<!--
Move the kops binary in to your PATH.
-->
将 kops 二进制文件移到你的 PATH 下:
```shell
sudo mv kops-darwin-amd64 /usr/local/bin/kops
```
你也可以使用 [Homebrew](https://brew.sh/) 安装 kops
```shell
brew update && brew install kops
```
{{% /tab %}}
{{% tab name="Linux" %}}
<!--
Download the latest release with the command:
-->
使用命令下载最新发布版本:
```shell
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
```
<!--
To download a specific version of kops, replace the following portion of the command with the specific kops version.
-->
要下载 kops 的特定版本,用特定的 kops 版本替换下面命令中的部分:
```shell
$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)
```
<!--
For example, to download kops version v1.20.0 type:
-->
例如,要下载 kops v1.20 版本,输入:
```shell
curl -LO https://github.com/kubernetes/kops/releases/download/v1.20.0/kops-linux-amd64
```
<!--
Make the kops binary executable
-->
令 kops 二进制文件可执行:
```shell
chmod +x kops-linux-amd64
```
<!--
Move the kops binary in to your PATH.
-->
将 kops 二进制文件移到 PATH 下:
```shell
sudo mv kops-linux-amd64 /usr/local/bin/kops
```
你也可以使用 [Homebrew](https://docs.brew.sh/Homebrew-on-Linux)
来安装 kops
```shell
brew update && brew install kops
```
<!--
On Linux:
-->
在 Linux 上:
```shell
wget https://github.com/kubernetes/kops/releases/download/1.10.0/kops-linux-amd64
chmod +x kops-linux-amd64
mv kops-linux-amd64 /usr/local/bin/kops
```
{{% /tab %}}
{{< /tabs >}}
<!--
### (2/5) Create a route53 domain for your cluster
kops uses DNS for discovery, both inside the cluster and so that you can reach the kubernetes API server
kops uses DNS for discovery, both inside the cluster and outside, so that you can reach the kubernetes API server
from clients.
-->
### (2/5) 为你的集群创建一个 route53 域名
kops 在集群内部都使用 DNS 进行发现操作,因此你可以从客户端访问 kubernetes API 服务器。
kops 在集群内部和外部都使用 DNS 进行发现操作,这样你可以从客户端访问
kubernetes API 服务器。
<!--
kops has a strong opinion on the cluster name: it should be a valid DNS name. By doing so you will
@@ -120,8 +210,8 @@ kops 对集群名称有明显的要求:它应该是有效的 DNS 名称。这
You can, and probably should, use subdomains to divide your clusters. As our example we will use
`useast1.dev.example.com`. The API server endpoint will then be `api.useast1.dev.example.com`.
-->
你应该使用子域名来划分集群。作为示例,我们将使用域名 `useast1.dev.example.com`
然后API 服务器端点域名将为 `api.useast1.dev.example.com`
可以,或许应该使用子域名来划分集群。作为示例,我们将使用域名 `useast1.dev.example.com`
这样API 服务器端点域名将为 `api.useast1.dev.example.com`
<!--
A Route53 hosted zone can serve subdomains. Your hosted zone could be `useast1.dev.example.com`,
@@ -154,10 +244,10 @@ records at your domain registrar (e.g. `example.com` would need to be configured
例如,你需要在购买 `example.com` 的地方配置 `example.com`
<!--
This step is easy to mess up (it is the #1 cause of problems!) You can double-check that
Verify your route53 domain setup (it is the #1 cause of problems!). You can double-check that
your cluster is configured correctly if you have the dig tool by running:
-->
这一步很容易搞砸(这是问题的第一大原因!)
检查你的 route53 域已经被正确设置(这是导致问题的最常见原因!)
如果你安装了 dig 工具,则可以通过运行以下步骤再次检查集群是否配置正确:
```shell
@@ -187,8 +277,10 @@ administer the same clusters - this is much easier than passing around kubecfg f
to the S3 bucket will have administrative access to all your clusters, so you don't want to share it beyond
the operations team.
-->
多个集群可以使用同一 S3 存储桶,并且你可以在管理同一集群的同事之间共享一个 S3 存储桶 - 这比传递 kubecfg 文件容易得多。
但是有权访问 S3 存储桶的任何人都将拥有对所有集群的管理访问权限,因此你不想在运营团队之外共享它
多个集群可以使用同一 S3 存储桶,并且你可以在管理同一集群的同事之间共享一个
S3 存储桶 - 这比传递 kubecfg 文件容易得多
但是有权访问 S3 存储桶的任何人都将拥有对所有集群的管理访问权限,
因此你不想在运营团队之外共享它。
<!--
So typically you have one S3 bucket for each ops team (and often the name will correspond
@@ -200,7 +292,8 @@ to the name of the hosted zone above!)
In our example, we chose `dev.example.com` as our hosted zone, so let's pick `clusters.dev.example.com` as
the S3 bucket name.
-->
在我们的示例中,我们选择 `dev.example.com` 作为托管区域,因此我们选择 `clusters.dev.example.com` 作为 S3 存储桶名称。
在我们的示例中,我们选择 `dev.example.com` 作为托管区域,因此我们选择
`clusters.dev.example.com` 作为 S3 存储桶名称。
<!--
* Export `AWS_PROFILE` (if you need to select a profile for the AWS CLI to work)
@@ -210,17 +303,18 @@ the S3 bucket name.
-->
* 导出 `AWS_PROFILE` 文件(如果你需要选择一个配置文件用来使 AWS CLI 正常工作)
* 使用 `aws s3 mb s3://clusters.dev.example.com` 创建 S3 存储桶
* 你可以进行 `export KOPS_STATE_STORE=s3://clusters.dev.example.com` 操作,然后 kops 将默认使用此位置。
* 你可以进行 `export KOPS_STATE_STORE=s3://clusters.dev.example.com` 操作,
然后 kops 将默认使用此位置。
我们建议将其放入你的 bash profile 文件或类似文件中。
<!--
### (4/5) Build your cluster configuration
Run "kops create cluster" to create your cluster configuration:
Run `kops create cluster` to create your cluster configuration:
-->
### (4/5) 建立你的集群配置
运行 "kops create cluster" 以创建你的集群配置:
运行 `kops create cluster` 以创建你的集群配置:
`kops create cluster --zones=us-east-1c useast1.dev.example.com`
@@ -229,7 +323,8 @@ kops will create the configuration for your cluster. Note that it _only_ create
not actually create the cloud resources - you'll do that in the next step with a `kops update cluster`. This
give you an opportunity to review the configuration or change it.
-->
kops 将为你的集群创建配置。请注意,它_仅_创建配置,实际上并没有创建云资源 - 你将在下一步中使用 `kops update cluster` 进行配置。
kops 将为你的集群创建配置。请注意,它_仅_创建配置,实际上并没有创建云资源 -
你将在下一步中使用 `kops update cluster` 进行配置。
这使你有机会查看配置或进行更改。
<!--
@@ -312,18 +407,6 @@ See the [list of add-ons](/docs/concepts/cluster-administration/addons/) to expl
* 删除集群:`kops delete cluster useast1.dev.example.com --yes`
<!--
## Feedback
-->
## 反馈
<!--
* Slack Channel: [#kops-users](https://kubernetes.slack.com/messages/kops-users/)
* [GitHub Issues](https://github.com/kubernetes/kops/issues)
-->
* Slack 频道: [#kops-users](https://kubernetes.slack.com/messages/kops-users/)
* [GitHub Issues](https://github.com/kubernetes/kops/issues)
## {{% heading "whatsnext" %}}
<!--
@@ -332,7 +415,8 @@ See the [list of add-ons](/docs/concepts/cluster-administration/addons/) to expl
* See the `kops` [docs](https://github.com/kubernetes/kops) section for tutorials, best practices and advanced configuration options.
-->
* 了解有关 Kubernetes 的[概念](/zh/docs/concepts/) 和
[`kubectl`](/zh/docs/reference/kubectl/overview/) 的更多信息。
[`kubectl`](/zh/docs/reference/kubectl/overview/) 有关的更多信息。
* 了解 `kops` [高级用法](https://github.com/kubernetes/kops)。
* 请参阅 `kops` [文档](https://github.com/kubernetes/kops) 获取教程、最佳做法和高级配置选项。
* 请参阅 `kops` [文档](https://github.com/kubernetes/kops) 获取教程、
最佳做法和高级配置选项。
@@ -14,12 +14,17 @@ weight: 30
<!--
This quickstart helps to install a Kubernetes cluster hosted on GCE, Azure, OpenStack, AWS, vSphere, Packet (bare metal), Oracle Cloud Infrastructure (Experimental) or Baremetal with [Kubespray](https://github.com/kubernetes-sigs/kubespray).
-->
此快速入门有助于使用 [Kubespray](https://github.com/kubernetes-sigs/kubespray) 安装在 GCE、Azure、OpenStack、AWS、vSphere、Packet(裸机)、Oracle Cloud Infrastructure(实验性)或 Baremetal 上托管的 Kubernetes 集群。
此快速入门有助于使用 [Kubespray](https://github.com/kubernetes-sigs/kubespray)
安装在 GCE、Azure、OpenStack、AWS、vSphere、Packet(裸机)、Oracle Cloud
Infrastructure(实验性)或 Baremetal 上托管的 Kubernetes 集群。
<!--
Kubespray is a composition of [Ansible](https://docs.ansible.com/) playbooks, [inventory](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/ansible.md), provisioning tools, and domain knowledge for generic OS/Kubernetes clusters configuration management tasks. Kubespray provides:
-->
Kubespray 是一个由 [Ansible](https://docs.ansible.com/) playbooks、[清单(inventory](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/ansible.md)、供应工具和通用 OS/Kubernetes 集群配置管理任务的领域知识组成的。 Kubespray 提供:
Kubespray 是一个由 [Ansible](https://docs.ansible.com/) playbooks、
[清单(inventory](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/ansible.md)、
制备工具和通用 OS/Kubernetes 集群配置管理任务的领域知识组成的。
Kubespray 提供:
<!--
* a highly available cluster
@@ -50,17 +55,18 @@ Kubespray 是一个由 [Ansible](https://docs.ansible.com/) playbooks、[清单
To choose a tool which best fits your use case, read [this comparison](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/comparisons.md) to
[kubeadm](/docs/reference/setup-tools/kubeadm/) and [kops](/docs/setup/production-environment/tools/kops/).
-->
要选择最适合你的用例的工具,请阅读[此比较](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/comparisons.md)以
[kubeadm](/zh/docs/reference/setup-tools/kubeadm/) 和 [kops](/zh/docs/setup/production-environment/tools/kops/) 。
要选择最适合你的用例的工具,请阅读
[kubeadm](/zh/docs/reference/setup-tools/kubeadm/) 和
[kops](/zh/docs/setup/production-environment/tools/kops/) 之间的
[这份比较](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/comparisons.md)。
<!-- body -->
<!--
## Creating a cluster
### (1/5) Meet the underlay requirements
-->
## 创建集群
### 1/5)满足下层设施要求
@@ -81,11 +87,14 @@ Provision servers with the following [requirements](https://github.com/kubernete
-->
* 在将运行 Ansible 命令的计算机上安装 Ansible v2.9 和 python-netaddr
* **运行 Ansible Playbook 需要 Jinja 2.11(或更高版本)**
* 目标服务器必须有权访问 Internet 才能拉取 Docker 镜像。否则,需要其他配置([请参见离线环境](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/offline-environment.md)
* 目标服务器必须有权访问 Internet 才能拉取 Docker 镜像。否则,
需要其他配置([请参见离线环境](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/offline-environment.md)
* 目标服务器配置为允许 IPv4 转发
* **你的 SSH 密钥必须复制**到清单中的所有服务器部分
* 防火墙不受管理,你将需要按照以前的方式实施自己的规则。为了避免在部署过程中出现任何问题,你应该禁用防火墙
* 如果从非 root 用户帐户运行 kubespray,则应在目标服务器中配置正确的特权升级方法。然后应指定“ansible_become” 标志或命令参数 “--become” 或 “-b”
* 防火墙不受管理,你将需要按照以前的方式实施自己的规则。
为了避免在部署过程中出现任何问题,你应该禁用防火墙
* 如果从非 root 用户帐户运行 kubespray,则应在目标服务器中配置正确的特权升级方法。
然后应指定“ansible_become” 标志或命令参数 “--become” 或 “-b”
<!--
Kubespray provides the following utilities to help provision your environment:
@@ -105,16 +114,18 @@ Kubespray 提供以下实用程序来帮助你设置环境:
<!--
### (2/5) Compose an inventory file
After you provision your servers, create an [inventory file for Ansible](https://docs.ansible.com/ansible/intro_inventory.html). You can do this manually or via a dynamic inventory script. For more information, see "[Building your own inventory](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/getting-started.md#building-your-own-inventory)".
After you provision your servers, create an [inventory file for Ansible](https://docs.ansible.com/ansible/latest/network/getting_started/first_inventory.html). You can do this manually or via a dynamic inventory script. For more information, see "[Building your own inventory](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/getting-started.md#building-your-own-inventory)".
### (3/5) Plan your cluster deployment
Kubespray provides the ability to customize many aspects of the deployment:
-->
### 2/5)编写清单文件
设置服务器后,请创建一个 [Ansible 的清单文件](https://docs.ansible.com/ansible/intro_inventory.html)。你可以手动执行此操作,也可以通过动态清单脚本执行此操作。有关更多信息,请参阅“[建立你自己的清单](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/getting-started.md#building-your-own-inventory)”。
设置服务器后,请创建一个
[Ansible 的清单文件](https://docs.ansible.com/ansible/latest/network/getting_started/first_inventory.html)。
你可以手动执行此操作,也可以通过动态清单脚本执行此操作。有关更多信息,请参阅
“[建立你自己的清单](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/getting-started.md#building-your-own-inventory)”。
### 3/5)规划集群部署
@@ -146,11 +157,12 @@ Kubespray 能够自定义部署的许多方面:
* 证书生成方式
<!--
Kubespray customizations can be made to a [variable file](https://docs.ansible.com/ansible/playbooks_variables.html). If you are just getting started with Kubespray, consider using the Kubespray defaults to deploy your cluster and explore Kubernetes.
Kubespray customizations can be made to a [variable file](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html). If you are just getting started with Kubespray, consider using the Kubespray defaults to deploy your cluster and explore Kubernetes.
-->
可以修改[变量文件](https://docs.ansible.com/ansible/playbooks_variables.html)以进行 Kubespray 定制。
如果你刚刚开始使用 Kubespray,请考虑使用 Kubespray 默认设置来部署你的集群并探索 Kubernetes 。
可以修改[变量文件](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html)
以进行 Kubespray 定制。
如果你刚刚开始使用 Kubespray,请考虑使用 Kubespray 默认设置来部署你的集群
并探索 Kubernetes 。
<!--
### (4/5) Deploy a Cluster
@@ -158,12 +170,12 @@ Next, deploy your cluster:
Cluster deployment using [ansible-playbook](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/getting-started.md#starting-custom-deployment).
-->
### 4/5)部署集群
接下来,部署你的集群:
使用 [ansible-playbook](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/getting-started.md#starting-custom-deployment) 进行j集群部署。
使用 [ansible-playbook](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/getting-started.md#starting-custom-deployment)
进行集群部署。
```shell
ansible-playbook -i your/inventory/inventory.ini cluster.yml -b -v \
@@ -172,7 +184,9 @@ ansible-playbook -i your/inventory/inventory.ini cluster.yml -b -v \
<!--
Large deployments (100+ nodes) may require [specific adjustments](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/large-deployments.md) for best results.
-->
大型部署(超过 100 个节点)可能需要[特定的调整](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/large-deployments.md),以获得最佳效果。
大型部署(超过 100 个节点)可能需要
[特定的调整](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/large-deployments.md)
以获得最佳效果。
<!--
### (5/5) Verify the deployment
@@ -181,7 +195,8 @@ Kubespray provides a way to verify inter-pod connectivity and DNS resolve with [
-->
### 5/5)验证部署
Kubespray 提供了一种使用 [Netchecker](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/netcheck.md)
Kubespray 提供了一种使用
[Netchecker](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/netcheck.md)
验证 Pod 间连接和 DNS 解析的方法。
Netchecker 确保 netchecker-agents pod 可以解析。
DNS 请求并在默认名称空间内对每个请求执行 ping 操作。
@@ -241,16 +256,17 @@ When running the reset playbook, be sure not to accidentally target your product
-->
## 反馈
* Slack 频道:[#kubespray](https://kubernetes.slack.com/messages/kubespray/)(你可以在[此处](https://slack.k8s.io/)获得邀请)
* Slack 频道:[#kubespray](https://kubernetes.slack.com/messages/kubespray/)
(你可以在[此处](https://slack.k8s.io/)获得邀请)
* [GitHub 问题](https://github.com/kubernetes-sigs/kubespray/issues)
<!--
## {{% heading "whatsnext" %}}
Check out planned work on Kubespray's [roadmap](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/roadmap.md).
-->
## {{% heading "whatsnext" %}}
查看有关 Kubespray 的[路线图](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/roadmap.md)的计划工作。
查看有关 Kubespray 的
[路线图](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/roadmap.md)
的计划工作。