什么是基础架构即代码 (IaC) 的示例?
What is an example of Infrastructure as a Code(IaC)?
我运行多次进入单词"IaaC"(或IaC)。当我用谷歌搜索时,它告诉我:
Infrastructure as code(IaC) is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.
Kubernetes中使用的yaml文件可以作为IaC的例子吗?也许甚至 Dockerfile 也可以这样考虑?如果没有,你能给我一些 IaC 的例子吗?
例如:
apiVersion: v1
kind: Service
metadata:
name: my-nginx-svc
labels:
app: nginx
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
IP Ops 需要对 release/update 互联网上的应用程序 运行 执行许多步骤。任务的几个例子是
配置新的虚拟机,例如使用所需的内存和规格启动 VM。
安装需要的软件和依赖
管理和扩展基础架构。
一次又一次地重复我们所做的所有配置。
基础架构即代码意味着自动化在 Internet 上部署我们的应用程序所需的步骤。由于使用 docker 和 k8s 我们正在自动化部署过程,因此它也被视为基础设施即代码。
例子
# define services (containers) that should be running
services:
mongo-database:
image: mongo:3.2
# what volumes to attach to this container
volumes:
- mongo-data:/data/db
# what networks to attach this container
networks:
- raddit-network
raddit-app:
# path to Dockerfile to build an image and start a container
build: .
environment:
- DATABASE_HOST=mongo-database
ports:
- 9292:9292
networks:
- raddit-network
# start raddit-app only after mongod-database service was started
depends_on:
- mongo-database
# define volumes to be created
volumes:
mongo-data:
# define networks to be created
networks:
raddit-network:
这个 docker compose 文件安装依赖项 mongo-database 本身也安装主应用程序 raddit-app,并指定应用程序侦听的端口。
我运行多次进入单词"IaaC"(或IaC)。当我用谷歌搜索时,它告诉我:
Infrastructure as code(IaC) is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.
Kubernetes中使用的yaml文件可以作为IaC的例子吗?也许甚至 Dockerfile 也可以这样考虑?如果没有,你能给我一些 IaC 的例子吗?
例如:
apiVersion: v1
kind: Service
metadata:
name: my-nginx-svc
labels:
app: nginx
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
IP Ops 需要对 release/update 互联网上的应用程序 运行 执行许多步骤。任务的几个例子是
配置新的虚拟机,例如使用所需的内存和规格启动 VM。
安装需要的软件和依赖
管理和扩展基础架构。
一次又一次地重复我们所做的所有配置。
基础架构即代码意味着自动化在 Internet 上部署我们的应用程序所需的步骤。由于使用 docker 和 k8s 我们正在自动化部署过程,因此它也被视为基础设施即代码。
例子
# define services (containers) that should be running
services:
mongo-database:
image: mongo:3.2
# what volumes to attach to this container
volumes:
- mongo-data:/data/db
# what networks to attach this container
networks:
- raddit-network
raddit-app:
# path to Dockerfile to build an image and start a container
build: .
environment:
- DATABASE_HOST=mongo-database
ports:
- 9292:9292
networks:
- raddit-network
# start raddit-app only after mongod-database service was started
depends_on:
- mongo-database
# define volumes to be created
volumes:
mongo-data:
# define networks to be created
networks:
raddit-network:
这个 docker compose 文件安装依赖项 mongo-database 本身也安装主应用程序 raddit-app,并指定应用程序侦听的端口。