目录
yaml案例
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "32"
creationTimestamp: "2024-01-29T09:27:30Z"
generation: 239
managedFields:
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:spec:
f:replicas: {}
manager: kube-controller-manager
operation: Update
subresource: scale
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:spec:
f:progressDeadlineSeconds: {}
f:revisionHistoryLimit: {}
f:selector: {}
f:strategy:
f:rollingUpdate:
.: {}
f:maxSurge: {}
f:maxUnavailable: {}
f:type: {}
f:template:
f:metadata:
f:annotations:
.: {}
f:eks.tke.cloud.tencent.com/cpu-type: {}
f:eks.tke.cloud.tencent.com/host-sysctls: {}
f:labels:
.: {}
f:app: {}
f:spec:
f:containers:
k:{"name":"main"}:
.: {}
f:command: {}
f:env:
.: {}
k:{"name":"APPLICATION_NAME"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"NACOS_PASSWORD"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"NACOS_USERNAME"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"PORT"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"PROFILE"}:
.: {}
f:name: {}
f:value: {}
k:{"name":"TZ"}:
.: {}
f:name: {}
f:value: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:ports:
.: {}
k:{"containerPort":80,"protocol":"TCP"}:
.: {}
f:containerPort: {}
f:protocol: {}
f:resources:
.: {}
f:limits:
.: {}
f:cpu: {}
f:memory: {}
f:requests:
.: {}
f:cpu: {}
f:memory: {}
f:securityContext:
.: {}
f:privileged: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:dnsPolicy: {}
f:imagePullSecrets:
.: {}
k:{"name":"api-secret"}: {}
f:initContainers:
.: {}
k:{"name":"setsysctl"}:
.: {}
f:command: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:resources: {}
f:securityContext:
.: {}
f:privileged: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
manager: tke-platform-test
operation: Update
time: "2024-05-07T07:07:51Z"
- apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:deployment.kubernetes.io/revision: {}
f:status:
f:availableReplicas: {}
f:conditions:
.: {}
k:{"type":"Available"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
k:{"type":"Progressing"}:
.: {}
f:lastTransitionTime: {}
f:lastUpdateTime: {}
f:message: {}
f:reason: {}
f:status: {}
f:type: {}
f:observedGeneration: {}
f:readyReplicas: {}
f:replicas: {}
f:updatedReplicas: {}
manager: kube-controller-manager
operation: Update
subresource: status
time: "2024-05-08T02:15:23Z"
name: test-deployment
namespace: default
resourceVersion: "21070137366"
uid: 4b8f7c6c-60b5-4c9c-b545-782d0bca5ec2
spec:
progressDeadlineSeconds: 600
replicas: 17
revisionHistoryLimit: 10
selector:
matchLabels:
app: test-deployment
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
annotations:
eks.tke.cloud.tencent.com/cpu-type: amd
eks.tke.cloud.tencent.com/host-sysctls: '[{"name": "kernel.core_pattern","value":
"/tmp/cores/core.%h.%e.%p.%t"}]'
creationTimestamp: null
labels:
app: test-deployment
spec:
containers:
- command:
- /bin/bash
- -c
- java -server -Xms12g -Xmx12g -jar /ysx-server-test.jar --spring.profiles.active=$PROFILE --server.port=$PORT --spring.application.name=$APPLICATION_NAME
--spring.cloud.nacos.username=$NACOS_USERNAME --spring.cloud.nacos.password=$NACOS_PASSWORD
env:
- name: PROFILE
value: 1n
- name: PORT
value: "8066"
- name: APPLICATION_NAME
value: ad_test_1n
- name: NACOS_USERNAME
value: nacos
- name: NACOS_PASSWORD
value: adcenter1N2BC
- name: TZ
value: Asia/Shanghai
image: advertise.tencentcloudcr.com/advertise/test-1n:20240507150432-ddd578f
imagePullPolicy: Always
name: main
ports:
- containerPort: 80
protocol: TCP
resources:
limits:
cpu: "8"
memory: 16Gi
requests:
cpu: "8"
memory: 16Gi
securityContext:
privileged: false
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: api-secret
initContainers:
- command:
- sh
- -c
- |-
sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.ip_local_reserved_ports=9100
sysctl -w net.ipv4.ip_local_port_range="1024 61999"
sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w fs.file-max=1048576
image: ccr.ccs.tencentyun.com/tkeimages/busybox:latest
imagePullPolicy: Always
name: setsysctl
resources: {}
securityContext:
privileged: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 17
conditions:
- lastTransitionTime: "2024-05-05T23:42:24Z"
lastUpdateTime: "2024-05-05T23:42:24Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2024-01-29T09:27:30Z"
lastUpdateTime: "2024-05-07T07:09:40Z"
message: ReplicaSet "test-deployment-7bb64d9f48" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 239
readyReplicas: 17
replicas: 17
updatedReplicas: 17
yaml解析
这个 YAML 文件描述了一个 Kubernetes 中的 Deployment 对象,包含了 Pod 的配置信息。让我来解释每个节点的含义:
-
apiVersion: apps/v1
:指定了 API 版本号。 -
kind: Deployment
:指定了 Kubernetes 中的资源类型,这里是 Deployment。
让我们逐个解释每个节点下面的信息:
-
metadata(元数据):
-
annotations(注解): 包含了一些与资源相关的注解信息,如部署的修订版本和创建时间等。
-
creationTimestamp(创建时间戳): 表示资源的创建时间。
-
generation(生成器): 表示资源的当前版本号。
-
-
spec(规格):
-
replicas(副本数): 指定了部署的副本数为 17 个。
-
revisionHistoryLimit(修订历史限制): 指定了 Deployment 的修订历史记录数限制为 10。
-
selector(选择器): 定义了用于选择 Pod 的标签。
-
strategy(策略): 定义了 Deployment 的更新策略,包括滚动更新的最大扩展和最大不可用的百分比。
-
template(模板): 定义了 Pod 的模板,包括容器的镜像、环境变量、资源限制等。
-
-
status(状态):
-
availableReplicas(可用副本数): 表示当前可用的副本数为 17 个。
-
conditions(条件): 表示 Deployment 的当前状态条件,如可用性和进度等。
-
observedGeneration(观察到的生成器): 表示观察到的 Deployment 的版本号。
-
readyReplicas(就绪副本数): 表示当前就绪的副本数为 17 个。
-
replicas(副本数): 表示当前的副本数为 17 个。
-
updatedReplicas(更新副本数): 表示当前更新完成的副本数为 17 个。
-
-
template(模板):
-
containers(容器): 定义了主容器列表,这里只有一个容器。
-
image(镜像): 定义了容器的镜像。
-
env(环境变量): 定义了容器的环境变量,如应用名称、端口号等。
-
ports(端口): 定义了容器暴露的端口,这里暴露了 80 端口。
-
resources(资源需求和限制): 定义了容器的资源需求和限制,包括 CPU 和内存,限制了 CPU 使用量为 8 个核心,内存为 16GB。
-
securityContext(安全上下文): 定义了容器的安全上下文,如是否具有特权等。
-
-
initContainers(初始化容器): 定义了初始化容器列表,这些容器将在主容器启动之前执行一些初始化操作。
-
这个 YAML 文件描述了一个部署了一个包含 17 个副本的 Pod,每个副本中运行一个名为 main
的容器,使用了指定的镜像和配置。