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_OPTS
value: ${java_opts}
image: ${app_docker_image}
imagePullPolicy: Always
livenessProbe:
failureThreshold: 5
httpGet:
path: /actuator/health
port: ${app_port}
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: ${app_name}
ports:
- containerPort: ${app_port}
name: http
protocol: TCP
readinessProbe:
failureThreshold: 5
httpGet:
path: /actuator/health
port: ${app_port}
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 60
successThreshold: 1
timeoutSeconds: 5
resources:
limits:
cpu: ${app_cpu_limit}
memory: {app_memory_limit}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: harbor
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
---
apiVersion: v1
kind: Service
metadata:
labels:
app: ${app_labels}
name: ${app_service_name}
namespace: ${app_namespace}
spec:
clusterIP: None
ports:
- name: ${app_service_name}
port: ${app_port}
protocol: TCP
targetPort: ${app_port}
selector:
app: ${app_labels}
sessionAffinity: None
type: 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