一、k8s yaml文件的用处
Kubernetes 对象是 “目标性记录” —— 一旦创建对象,Kubernetes 系统将持续工作以确保对象存在。 通过创建对象,本质上是在告知 Kubernetes 系统,所需要的集群工作负载看起来是什么样子的, 这就是 Kubernetes 集群的 期望状态(Desired State)。
yaml文件就是用来描述你的应用启动需要达到一个什么样的状态。
二、必需字段
在想要创建的 Kubernetes 对象对应的 .yaml 文件中,需要配置如下的字段:
apiVersion - 创建该对象所使用的 Kubernetes API 的版本
kind - 想要创建的对象的类别
metadata - 帮助唯一性标识对象的一些数据,包括一个 name 字符串、UID 和可选的 namespace
spec - 你所期望的该对象的状态
Deployment 控制器yaml
apiVersion: apps/v1 #api
kind: Deployment #控制器类型
metadata: #元数据
annotations:
deployment.kubernetes.io/revision: "14"
description: nuwa-sso
generation: 17
labels:
k8s-app: nuwa-sso
qcloud-app: nuwa-sso
name: nuwa-sso
namespace: nvwa-test
spec:
minReadySeconds: 10
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector: # 正确的Deployment书写方式,是要让spec.selector.matchLabels值和spec.template.metadata.lables值完全匹配,这样才不会报错
matchLabels:
k8s-app: nuwa-sso
qcloud-app: nuwa-sso
strategy:
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
k8s-app: nuwa-sso
qcloud-app: nuwa-sso
spec:
containers:
- image: dockerdev.gwmfc.com/cmp-refactor/nuwa-sso:1.0.0.52.test
imagePullPolicy: Always
name: nuwa-sso
resources:
limits:
memory: 1536Mi
requests:
cpu: 250m
memory: 512Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
hostNetwork: true
imagePullSecrets:
- name: dockerdev
nodeSelector:
type: gateway
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
statefulset 控制器yaml
文档更新时间: 2022-03-29 15:53 作者:张尚