欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 美食 > k8s服务StatefulSet部署模板

k8s服务StatefulSet部署模板

2025/1/24 7:16:48 来源:https://blog.csdn.net/weixin_45277567/article/details/145306639  浏览:    关键词:k8s服务StatefulSet部署模板

java 服务StatefulSet部署模板

vim templates-test.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:labels:app: ${app_labels}name: ${app_name}namespace: ${app_namespace}
spec:replicas: ${app_replicas_count}selector:matchLabels:app: ${app_labels}template:labels:app: ${app_labels}spec:containers:- env:- name: JAVA_OPTSvalue: ${java_opts}image: ${app_docker_image}imagePullPolicy: AlwayslivenessProbe:failureThreshold: 5httpGet:path: /actuator/healthport: ${app_port}scheme: HTTPinitialDelaySeconds: 120periodSeconds: 10successThreshold: 1timeoutSeconds: 5name: ${app_name}ports:- containerPort: ${app_port}name: httpprotocol: TCPreadinessProbe:failureThreshold: 5httpGet:path: /actuator/healthport: ${app_port}scheme: HTTPinitialDelaySeconds: 120periodSeconds: 60successThreshold: 1timeoutSeconds: 5resources:limits:cpu: ${app_cpu_limit}memory: {app_memory_limit}terminationMessagePath: /dev/termination-logterminationMessagePolicy: FilednsPolicy: ClusterFirstimagePullSecrets:- name: harborrestartPolicy: AlwaysschedulerName: default-schedulersecurityContext: {}terminationGracePeriodSeconds: 30updateStrategy:rollingUpdate:partition: 0type: RollingUpdate
---
apiVersion: v1
kind: Service
metadata:labels:app: ${app_labels}name: ${app_service_name}namespace: ${app_namespace}
spec:clusterIP: Noneports:- name: ${app_service_name}port: ${app_port}protocol: TCPtargetPort: ${app_port}selector:app: ${app_labels}sessionAffinity: Nonetype: ClusterIP
status:loadBalancer: {}

涉及到的变量

 ${app_labels}${app_name}${app_namespace}${app_replicas_count}${java_opts}${app_docker_image}${app_port}${app_cpu_limit}{app_memory_limit}
${app_service_name}

测试示例

设置环境变量

export app_labels=test-lable
export app_name=test-name
export app_namespace=test-ns
export app_replicas_count=1
export java_opts="-xms=100mi -xms=100mi -xms=100mi"
export app_docker_image=docker.io/library/openjdk:8-jdk-alpine
export app_port=10000
export app_cpu_limit=1
export app_memory_limit=1000mi
export app_service_name=test-svc-name

执行替换

  envsubst \'\${app_name},\${app_namespace},\${app_labels},\${app_replicas_count},\${java_opts}\,\${app_docker_image}\,\${app_port}\,\${app_cpu_limit}\,\${app_memory_limit}\,\${app_service_name}\' < /root/test/templates-test.yaml > /root/test/templates-new.yaml

查看新文件 templates-new.yaml

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com