Files
compose-template/Test/Kubernetes/nginx/nginx-deployment.yaml
2022-07-04 19:14:22 +08:00

61 lines
2.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
apiVersion: apps/v1 #与k8s集群版本有关使用 kubectl api-versions 即可查看当前集群支持的版本
kind: Deployment #该配置的类型,我们使用的是 Deployment
metadata: #译名为元数据,即 Deployment 的一些基本属性和信息
name: nginx-deployment #Deployment 的名称
namespace: nginx
labels: #标签可以灵活定位一个或多个资源其中key和value均可自定义可以定义多组目前不需要理解 Job、Deployment、ReplicaSet 和 DaemonSet 同时支持基于等式的选择方式和基于集合的选择方式
app: nginx #为该Deployment设置key为appvalue为nginx的标签
annotations: #注释
key1: value1
key2: value2
spec: #这是关于该Deployment的描述可以理解为你期待该Deployment在k8s中如何使用
replicas: 3 #使用该Deployment创建一个应用程序实例
revisionHistoryLimit: 10 # 该Deployment保留多少个旧的ReplicaSet
selector: #标签选择器,与上面的标签共同作用,目前不需要理解
matchLabels: #选择包含标签app:nginx的资源
app: nginx
template: #这是选择或创建的Pod的模板
metadata: #Pod的元数据
labels: #Pod的标签上面的selector即选择包含标签app:nginx的Pod
app: nginx
spec: #期望Pod实现的功能即在pod中部署
containers: #生成container与docker中的container是同一种 containers
- name: nginx #container的名称
image: nginx:1.23.0 #使用镜像nginx:1.7.9创建container该container默认80端口可访问
ports:
- containerPort: 80
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
preStop:
exec:
command: ["/bin/sh", "-c", "nginx -s quit; while killall -o nginx; do sleep 1; done"]
resources:
limits:
cpu: 100m
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
# These containers are run during pod initialization
initContainers:
- name: install
image: busybox
command:
- wget
- "-O"
- "/work-dir/index.html"
- https://kuboard.cn
volumeMounts:
- name: workdir
mountPath: "/work-dir"
dnsPolicy: Default
volumes:
- name: workdir
emptyDir: {}