yaml实例
deployment:
--- apiVersion: apps/v1beta1 kind: Deployment metadata: name: nginx-deploy labels: app: nginx spec: # 副本数 replicas: 3 # 允许保留历史版本的数量 revisionHistoryLimit: 15 # 5秒之后执行操作 minReadySeconds: 5 strategy: # 升级 type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.10.0 ports: - containerPort: 80
wordpress:
---
# 创建mysql数据库
apiVersion: apps/v1beta1 kind: Deployment metadata: name: mysql-deploy
# 名称空间 namespace: blog labels: app: mysql spec: template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:5.7
# 有镜像存在就用,不另外去pull imagePullPolicy: IfNotPresent ports: - containerPort: 3306 name: dbport
# 环境变量 env: - name: MYSQL_ROOT_PASSWORD value: rootPassW0rd - name: MYSQL_DATABASE value: wordpress - name: MYSQL_USER value: wordpress - name: MYSQL_PASSWORD value: wordpress
# 挂载 volumeMounts: - name: db
# 容器内的目录 mountPath: /var/lib/mysql volumes: - name: db
# 宿主机目录 hostPath: path: /var/lib/mysql
---
# 创建service,默认ClusterIP(使各个pod都能访问mysql) apiVersion: v1 kind: Service metadata: name: mysql
# 名称空间 namespace: blog spec: selector: app: mysql ports: - name: mysqlport protocol: TCP port: 3306
# mysql容器端口(填写mysql端口name是为了修改mysql端口后无需修改这里的端口,可以说是可扩展性) targetPort: dbport ---
# 创建wordpress apiVersion: apps/v1beta1 kind: Deployment metadata: name: wordpress-deploy
# 名称空间 namespace: blog labels: app: wordpress spec:
# 允许保留历史版本的数量 revisionHistoryLimit: 10
# 5秒之后执行操作 minReadySeconds: 5
# 滚动升级策略 strategy: type: RollingUpdate rollingUpdate:
#容器副本最大数量
maxSurge: 1
# 容器副本停止的最大数量 maxUnavailable: 1 template: metadata: labels: app: wordpress spec:
# 在主容器启动前执行(初始化操作) initContainers: - name: init-db image: busybox
# 通过查询mysql服务名是否可以解析来判定mysql服务是否可用,如果可以解析则init容器退出码为0,应用容器正常初始化;否则直到可以解析mysql服务名才退出 command: ['sh','-c','until nslookup mysql; do echo waiting for mysql service; sleep 2; done;'] containers: - name: wordpress image: wordpress imagePullPolicy: IfNotPresent ports: - containerPort: 80 name: wdport env: - name: WORDPRESS_DB_HOST value: mysql:3306 - name: WORDPRESS_DB_USER value: wordpress - name: WORDPRESS_DB_PASSWORD value: wordpress
# 通过tcpSocket检测应用程序80端口是否正常运行 livenessProbe: tcpSocket: port: 80
# 容器启动后第一次执行探测需要等待多少秒 initialDelaySeconds: 10
# 每3秒执行一次探测 periodSeconds: 3
# 检测服务是否已经准备好对外提供服务 readinessProbe: tcpSocket: port: 80 initialDelaySeconds: 15 periodSeconds: 10
# 资源限制 resources:
# 最高上限(不允许突破) limits: cpu: 200m memory: 200Mi
# 设置资源的一个最小保证值 requests: cpu: 100m memory: 100Mi --- apiVersion: v1 kind: Service metadata: name: wordpress
# 名称空间 namespace: blog spec: selector: app: wordpress type: NodePort ports: - name: wordpressport protocol: TCP port: 80 nodePort: 30746 targetPort: wdport
Jenkins YAML
apiVersion: v1 kind: Namespace metadata: name: kube-cicd --- apiVersion: v1 kind: PersistentVolume metadata: name: jenkinspv labels: name: jenkinspv spec: nfs: path: /jenkins server: 10.4.7.21 accessModes: ["ReadWriteMany"] capacity: storage: 2Gi --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: jenkinspv namespace: kube-cicd spec: accessModes: ["ReadWriteMany"] resources: requests: storage: 2Gi --- kind: Service apiVersion: v1 metadata: labels: app: jenkins name: jenkins namespace: kube-cicd spec: type: NodePort ports: - port: 8080 name: web nodePort: 30888 targetPort: jenkinsport selector: app: jenkins --- kind: Deployment apiVersion: apps/v1 metadata: name: jenkins namespace: kube-cicd labels: app: jenkins spec: replicas: 1 selector: matchLabels: app: jenkins template: metadata: labels: app: jenkins name: jenkins spec: volumes: - name: jenkinshome persistentVolumeClaim: claimName: jenkinspv containers: - name: jenkins image: registry.cn-chengdu.aliyuncs.com/kube-cicd/aweidada/jenkins:pw ports: - containerPort: 8080 name: jenkinsport protocol: TCP env: - name: JAVA_OPTS value: -Xmx512m -Xms512m volumeMounts: - name: jenkinshome mountPath: /var/jenkins_home securityContext: runAsUser: 0 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 0 revisionHistoryLimit: 7 progressDeadlineSeconds: 600
本文来自博客园,作者:MegaloBox,转载请注明原文链接:https://www.cnblogs.com/cpw6/p/12590241.html