{"id":1203,"date":"2023-03-28T10:32:46","date_gmt":"2023-03-28T02:32:46","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1203"},"modified":"2023-04-07T09:53:05","modified_gmt":"2023-04-07T01:53:05","slug":"k8s-deployment-service-yaml-template","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/","title":{"rendered":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f"},"content":{"rendered":"
deployment.yaml<\/p>\n
apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n labels:\n app: ${NAME} #\u670d\u52a1\u540d\u79f0\n name: ${NAME}\n namespace: ${NAMESPACE} #\u540d\u79f0\u7a7a\u95f4\nspec:\n replicas: 2\n selector:\n matchLabels:\n app: ${NAME}\n strategy:\n rollingUpdate:\n maxSurge: 1\n maxUnavailable: 0\n type: RollingUpdate\n template:\n metadata:\n labels:\n app: ${NAME}\n spec:\n containers:\n - name: ${NAME}\n image: ${IMAGE} #\u955c\u50cf\u5730\u5740\n imagePullPolicy: IfNotPresent\n env:\n - name: SERVER_PORT\n value: ${SERVER_PORT} #\u670d\u52a1\u7aef\u53e3\uff0c\u540e\u7aef\u4e00\u822c8080\uff0c\u524d\u7aef80\n - name: DEPLOY_ENV\n value: ${DEPLOY_ENV} #\u90e8\u7f72\u73af\u5883 \n ports:\n - name: http\n containerPort: 8080\n protocol: TCP\n livenessProbe:\n failureThreshold: 3\n httpGet:\n path: \/health\n port: 8080\n scheme: HTTP\n periodSeconds: 5\n successThreshold: 1\n timeoutSeconds: 3\n readinessProbe:\n failureThreshold: 3\n httpGet:\n path: \/health\n port: 8080\n scheme: HTTP\n periodSeconds: 5\n successThreshold: 1\n timeoutSeconds: 3\n startupProbe:\n httpGet:\n path: \/health\n port: 8080\n failureThreshold: 60\n periodSeconds: 10\n timeoutSeconds: 3\n resources:\n requests:\n cpu: 500m\n memory: 2Gi\n limits:\n cpu: 1000m\n memory: 4Gi\n imagePullSecrets:\n - name: docker-secret #\u955c\u50cf\u62c9\u53d6secret<\/code><\/pre>\ningress.yaml <\/p>\n
apiVersion: networking.k8s.io\/v1\nkind: Ingress\nmetadata:\n annotations:\n kubernetes.io\/ingress.class: nginx\n name: ${NAME} #\u670d\u52a1\u540d\u79f0\uff0c\u548cdeployment\u540d\u79f0\u4e00\u6837\u5c31\u884c\n namespace: ${NAMESPACE} #\u540d\u79f0\u7a7a\u95f4\nspec:\n rules:\n - host: ${INGRESS_HOST} #\u57df\u540d\n http:\n paths:\n - pathType: Prefix\n path: \/ #\u8def\u5f84\n backend:\n service:\n name: ${NAME}\n port:\n number: 8080\n tls:\n - hosts:\n - ${INGRESS_HOST}\n secretName: ${INGRESS_HOST_SECRET} #\u57df\u540d\u8bc1\u4e66secret<\/code><\/pre>\n\u5e26\u4e8c\u7ea7\u76ee\u5f55\u7684ingress<\/p>\n
apiVersion: networking.k8s.io\/v1\nkind: Ingress\nmetadata:\n annotations:\n kubernetes.io\/ingress.class: nginx\n nginx.ingress.kubernetes.io\/rewrite-target: \/$2\n name: ${NAME}\n namespace: ${NAMESPACE}\nspec:\n rules:\n - host: ${INGRESS_HOST}\n http:\n paths:\n - pathType: Prefix\n path: \/${INGRESS_PATH}(\/|$)(.*) \n backend:\n service:\n name: ${NAME}\n port:\n number: 8080\n tls:\n - hosts:\n - ${INGRESS_HOST}\n secretName: ${INGRESS_HOST_SECRET}<\/code><\/pre>\nsvc.yaml<\/p>\n
apiVersion: v1\nkind: Service\nmetadata:\n name: ${NAME}\n namespace: ${NAMESPACE}\nspec:\n ports:\n - name: http\n port: 8080\n protocol: TCP\n targetPort: 8080\n selector:\n app: ${NAME}\n type: ClusterIP<\/code><\/pre>\nhpa.yaml<\/p>\n
apiVersion: autoscaling\/v2beta2\nkind: HorizontalPodAutoscaler\nmetadata:\n name: ${NAME}\n namespace: ${NAMESPACE}\nspec:\n scaleTargetRef:\n apiVersion: apps\/v1\n kind: Deployment\n name: ${NAME}\n minReplicas: 2\n maxReplicas: 10\n metrics:\n - type: Resource\n resource:\n name: cpu\n target:\n type: Utilization\n averageUtilization: 80\n # - type: Resource\n # resource:\n # name: memory\n # target:\n # type: Utilization\n # averageUtilization: 80\n# - type: Object\n# object:\n# metric:\n# name: requests-per-second\n# describedObject:\n# apiVersion: networking.k8s.io\/v1beta1\n# kind: Ingress\n# name: main-route\n# current:\n# value: 10k\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"deployment.yaml apiVersion: apps\/v1 kind: Deployment me<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"yoast_head":"\n
k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n