提交 c9bf84ea 编写于 作者: F feilong

完成Terraform

上级 3c822188
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "start_k8s_three_nodes.md",
"notebook_enable": false,
"exercise_id": "dc46afbe45344def85ffb7835cc9fd21"
......
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "config_view.md",
"notebook_enable": false,
"exercise_id": "e4ed448ebffb4d61b7c95fe763792efb"
......
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "create_deployment.md",
"notebook_enable": false,
"exercise_id": "9f699ea545304e6dbd354df5e63b3d96"
......
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "create_service.md",
"notebook_enable": false,
"exercise_id": "40ac07260ef34085961c39064ad61b09"
......
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "rs_pod.md",
"notebook_enable": false,
"exercise_id": "03679801cd5e4b2aad9c10f2adaad982"
......
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "introduce.md",
"notebook_enable": false,
"exercise_id": "067897924b1447589d6232c0b4aca432"
......
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "introduce.md",
"notebook_enable": false,
"exercise_id": "6c420e94227948279466358d4548c0d4"
......
{
"type": "code_options",
"author": null,
"author": "feilong",
"source": "introduce.md",
"notebook_enable": false,
"exercise_id": "e0d420a053a8499f8e42c3b29e673320"
......
{
"node_id": "cloud_native-9c2a74f5d85842ae895102786131545a",
"keywords": [],
"children": [],
"export": [
"introduce.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": null,
"source": "introduce.md",
"notebook_enable": false,
"exercise_id": "ab4f320185c64e9ea8a71d5928482709"
}
\ No newline at end of file
# 服务网格(ServiceMesh)
客户端请求网页常常会经过代理,代理请求后面的服务,后台服务返回给代理,代理再返回给客户端。这是一个典型的代理服务的情景。
现代后端开发,将服务拆分成多个微服务是常见的做法,微服务之间互相调用,每个服务都需要写一些路由代码。于是诞生了服务网格(ServiceMesh),服务网格是内置于应用程序中的专用基础架构层。
以下说法错误的是?
## 答案
使用了微服务,就一定要用服务网格(ServiceMesh).
## 选项
### A
服务网格将公共的服务间路由和共享数据逻辑抽象出来,作为一个基础架构层。
### B
微服务可以没有服务网格,每个服务自己写一些服务间路由代码。
### C
服务网格的特点是内置的基础架构层。
{
"node_id": "cloud_native-dcdf8cea6d814fc89adf10ce7e516a08",
"keywords": [],
"children": [],
"export": [
"install.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": null,
"source": "install.md",
"notebook_enable": false,
"exercise_id": "0e05870e435d4d90a0192aecbde5e8ff"
}
\ No newline at end of file
# {在此填写标题}
{在此填写题目描述}
## 答案
{在此填写答案}
## 选项
### A
{在此填写选项A}
### B
{在此填写选项B}
### C
{在此填写选项C}
{
"node_id": "cloud_native-80dec61abcca4348a6fdc9b9b727b486",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "cloud_native-851004ce780348c1a175c7530a00f0d8",
"keywords": [],
"children": [],
"export": [
"introduce.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": null,
"source": "introduce.md",
"notebook_enable": false,
"exercise_id": "f8534f83cea54f39bafb2720eb84a9b0"
}
\ No newline at end of file
# 什么是 Terraform
Terraform 是一个高度可扩展的工具,通过 Provider 来支持新的基础架构。Terraform能够让您在云上轻松使用 简单模板语言 来定义、预览和部署云基础结构。您可以使用Terraform来创建、修改、删除ECS、VPC、RDS、SLB等多种资源。
可以从两个方面来简化理解
* Terraform 采用声明式方式配置基础架构设置
* Terraform 提供了对规范的基础架构配置的命令行操作
Terraform 对基础架构的管理3个步骤
* Write: 编写基础架构的配置
* Plan: 对配置进行校验
* Apply: 将配置在多云上实施、生效
以下说法错误的是?
## 答案
Terraform 可以用来将基础设施部署到区块链
## 选项
### A
可以使用 Terraform 来创建、修改、删除ECS
### B
Terraform 为跨云基础设施构建提供了便利
### C
Terraform 采用声明式配置方式编程,符合云原生的风格
\ No newline at end of file
{
"node_id": "cloud_native-b6368923f8b04480a8345495b9da4a7c",
"keywords": [],
"children": [],
"export": [
"install.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": null,
"source": "install.md",
"notebook_enable": false,
"exercise_id": "7ab9d5025ef04a6c96e3a7ff3d5840a6"
}
\ No newline at end of file
# 使用 Terraform 配置和构建基础设施
不同平台的[Terraform安装指南](https://learn.hashicorp.com/tutorials/terraform/install-cli)
例如,MacOS上的安装命令:
```bash
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
```
安装成功如图:
![](./img/install.png)
查看下有哪些命令:
![](./img/commands.png)
可以看到一组核心命令:
* init: 初始化目录
* validate: 检测配置是否有效
* plan:计划,显示当前配置的依赖变动
* apply: 创建或者应用基础设施配置
* destroy:销毁配置的创建
例如,这是一个'app.tf' 配置,配置了docker部署相关的配置,我们的目的只是理解 Terraform 是干什么的,细节不用太细究。
```bash
terraform {
required_providers {
docker = {
source = "terraform-providers/docker"
}
}
}
provider "docker" {
host = "tcp://localhost:2375"
}
resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "tutorial"
ports {
internal = 80
external = 8000
}
}
```
现在,执行`terraform init`命令初始化
![](./img/init.png)
现在,执行`terraform plan`命令检测配置
![](./img/plan.png)
可以看到,由于连不上 Mac系统的 docker daemon ,环境监测失败。Mac系统上不需要配置`host = "tcp://localhost:2375"`,删除后,重新执行如下
![](./img/plan_success.png)
现在,我们执行`terraform apply`,将会开始构建一个 ngix 的docker:
![](./img/apply_q.png)
在实际构建之前,会要求再次确认,输入'yes'回车,开始实施:
![](./img/apply_a.png)
可见,使用 terraform 可以让基础设施的构建使用上声明式配置,具有标准化、统一配置、减少错误、跨平台的好处。
以下说法错误的是?
## 答案
terraform 只能在MacOS上使用
## 选项
### A
terraform 可以大幅度简化基础设施构建
### B
terraform 命令行使用`init`, `plan`, `apply` 三个子命令来管理基础设施构建
### C
terraform 提供了后缀名为 tf 的声明式基础设施构建配置
\ No newline at end of file
......@@ -64,7 +64,7 @@
}
},
{
"容器编排(学习环境 kubernetes)": {
"容器编排(学习环境 k8s)": {
"node_id": "cloud_native-62126de2412e4f528827e9e4a192f894",
"keywords": [],
"children": [
......@@ -119,7 +119,7 @@
}
},
{
"容器编排(生产环境 kubernates)": {
"容器编排(生产环境 k8s)": {
"node_id": "cloud_native-be3fffb284e242489400a9c65ae1b217",
"keywords": [],
"children": [
......@@ -159,20 +159,39 @@
"服务网格(istio)": {
"node_id": "cloud_native-4ebf1370e7124635a812ccc4bd5cdc21",
"keywords": [],
"children": [
{
"ServiceMesh介绍": {
"node_id": "cloud_native-9c2a74f5d85842ae895102786131545a",
"keywords": [],
"children": [],
"keywords_must": [],
"keywords_forbid": []
}
},
{
"基础架构自动编排(Terraform)": {
"node_id": "cloud_native-97df8fbe24294dd6890622b4a7f01bbd",
"安装istio": {
"node_id": "cloud_native-dcdf8cea6d814fc89adf10ce7e516a08",
"keywords": [],
"children": [],
"keywords_must": [],
"keywords_forbid": []
}
},
{
"使用istio监控服务": {
"node_id": "cloud_native-80dec61abcca4348a6fdc9b9b727b486",
"keywords": [],
"children": [],
"keywords_must": [],
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
"持续集成和部署(Jenkins)": {
"node_id": "cloud_native-1c1ab3786e8a42668c7b5b79f6fc81a4",
......@@ -181,6 +200,34 @@
"keywords_must": [],
"keywords_forbid": []
}
},
{
"基础架构自动编排(Terraform)": {
"node_id": "cloud_native-97df8fbe24294dd6890622b4a7f01bbd",
"keywords": [],
"children": [
{
"介绍Terraform": {
"node_id": "cloud_native-851004ce780348c1a175c7530a00f0d8",
"keywords": [],
"children": [],
"keywords_must": [],
"keywords_forbid": []
}
},
{
"Terraform命令行工具": {
"node_id": "cloud_native-b6368923f8b04480a8345495b9da4a7c",
"keywords": [],
"children": [],
"keywords_must": [],
"keywords_forbid": []
}
}
],
"keywords_must": [],
"keywords_forbid": []
}
}
],
"keywords_must": [],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册