{"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>\n

ingress.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>\n

svc.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>\n

hpa.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":"\nk8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4<\/title>\n<meta name=\"description\" content=\"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\uff0c\u4f7f\u7528\u65f6\u7ed9\u53d8\u91cf\u8d4b\u503c\u5373\u53ef\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\" \/>\n<meta property=\"og:description\" content=\"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\uff0c\u4f7f\u7528\u65f6\u7ed9\u53d8\u91cf\u8d4b\u503c\u5373\u53ef\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-28T02:32:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-07T01:53:05+00:00\" \/>\n<meta name=\"author\" content=\"\u7ba1\u7406\u5458\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/\"},\"author\":{\"name\":\"\u7ba1\u7406\u5458\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"headline\":\"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\",\"datePublished\":\"2023-03-28T02:32:46+00:00\",\"dateModified\":\"2023-04-07T01:53:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/\"},\"wordCount\":12,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"articleSection\":[\"Kubernetes\"],\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/\",\"url\":\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/\",\"name\":\"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\",\"isPartOf\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#website\"},\"datePublished\":\"2023-03-28T02:32:46+00:00\",\"dateModified\":\"2023-04-07T01:53:05+00:00\",\"description\":\"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\uff0c\u4f7f\u7528\u65f6\u7ed9\u53d8\u91cf\u8d4b\u503c\u5373\u53ef\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#breadcrumb\"},\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.linuxdevops.cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"kubernetes\",\"item\":\"https:\/\/www.linuxdevops.cn\/kubernetes\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#website\",\"url\":\"https:\/\/www.linuxdevops.cn\/\",\"name\":\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\",\"description\":\"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\u7b14\u8bb0\",\"publisher\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\"},\"alternateName\":\"linuxdevops\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.linuxdevops.cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-CN\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1\",\"name\":\"\u7ba1\u7406\u5458\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-CN\",\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg\",\"contentUrl\":\"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg\",\"width\":512,\"height\":512,\"caption\":\"\u7ba1\u7406\u5458\"},\"logo\":{\"@id\":\"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/\"},\"description\":\"\u7ba1\u7406\u5458\",\"url\":\"https:\/\/www.linuxdevops.cn\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","description":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\uff0c\u4f7f\u7528\u65f6\u7ed9\u53d8\u91cf\u8d4b\u503c\u5373\u53ef\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/","og_locale":"zh_CN","og_type":"article","og_title":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","og_description":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\uff0c\u4f7f\u7528\u65f6\u7ed9\u53d8\u91cf\u8d4b\u503c\u5373\u53ef\u3002","og_url":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/","og_site_name":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","article_published_time":"2023-03-28T02:32:46+00:00","article_modified_time":"2023-04-07T01:53:05+00:00","author":"\u7ba1\u7406\u5458","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#article","isPartOf":{"@id":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/"},"author":{"name":"\u7ba1\u7406\u5458","@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"headline":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f","datePublished":"2023-03-28T02:32:46+00:00","dateModified":"2023-04-07T01:53:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/"},"wordCount":12,"commentCount":0,"publisher":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"articleSection":["Kubernetes"],"inLanguage":"zh-CN","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/","url":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/","name":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f - Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","isPartOf":{"@id":"https:\/\/www.linuxdevops.cn\/#website"},"datePublished":"2023-03-28T02:32:46+00:00","dateModified":"2023-04-07T01:53:05+00:00","description":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f\uff0c\u4f7f\u7528\u65f6\u7ed9\u53d8\u91cf\u8d4b\u503c\u5373\u53ef\u3002","breadcrumb":{"@id":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#breadcrumb"},"inLanguage":"zh-CN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.linuxdevops.cn\/2023\/03\/k8s-deployment-service-yaml-template\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.linuxdevops.cn\/"},{"@type":"ListItem","position":2,"name":"kubernetes","item":"https:\/\/www.linuxdevops.cn\/kubernetes\/"},{"@type":"ListItem","position":3,"name":"k8s \u751f\u4ea7\u7ea7\u901a\u7528yaml\u6a21\u677f"}]},{"@type":"WebSite","@id":"https:\/\/www.linuxdevops.cn\/#website","url":"https:\/\/www.linuxdevops.cn\/","name":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4","description":"Linux\u81ea\u52a8\u5316\u8fd0\u7ef4\u7b14\u8bb0","publisher":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1"},"alternateName":"linuxdevops","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.linuxdevops.cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-CN"},{"@type":["Person","Organization"],"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/3e206335d5796fdd8679e449df72a0d1","name":"\u7ba1\u7406\u5458","image":{"@type":"ImageObject","inLanguage":"zh-CN","@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/","url":"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg","contentUrl":"https:\/\/www.linuxdevops.cn\/wp-content\/uploads\/2019\/07\/cropped-index.jpg","width":512,"height":512,"caption":"\u7ba1\u7406\u5458"},"logo":{"@id":"https:\/\/www.linuxdevops.cn\/#\/schema\/person\/image\/"},"description":"\u7ba1\u7406\u5458","url":"https:\/\/www.linuxdevops.cn\/author\/root\/"}]}},"_links":{"self":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/1203"}],"collection":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/comments?post=1203"}],"version-history":[{"count":3,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/1203\/revisions"}],"predecessor-version":[{"id":1208,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/posts\/1203\/revisions\/1208"}],"wp:attachment":[{"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/media?parent=1203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/categories?post=1203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxdevops.cn\/wp-json\/wp\/v2\/tags?post=1203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}