欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

k8s的deploy、service、namespace模板

程序员文章站 2024-03-11 16:44:43
...

deploy.yaml

#Deployment
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    name: 003-paas-static-deploy
    namespace: paas-app-dev2
    labels:
        name: 003-paas-static-deploy
spec:
    replicas: 1
    template:
        metadata:
            labels:
                name: 003-paas-static-pod
        spec:
            terminationGracePeriodSeconds: 1  #k8s正确、优雅地关闭应用,等待时间30秒
            nodeSelector:
              dev2: "true"
            hostAliases:
            - ip: 10.111.181.127
              hostnames:
              - "config-server"
            containers:
            - name: "web"
              image: sinoeyes.io/dev2/paas-static:1.0.0
              ports:
              - containerPort: 20003
              env:
              - name: JavaOption
                value: -server -Xms128m -Xmx128m
              - name: "spring.cloud.config.uri"
                value: "http://config-server:31001/"
              - name: spring.cloud.config.profile
                value: dev2

service.yaml

#Service
apiVersion: v1
kind: Service
metadata:
    name: static
    namespace: paas-app-dev2
    labels:
        name: 003-paas-static
spec:
    selector:
        name: 003-paas-static-pod
    sessionAffinity: ClientIP
    type: NodePort
    ports:
    - name: "http"
      port: 20003
      targetPort: 20003

namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
   name: paas-cloud-dev2
   labels:
     name: paas-cloud-dev2
---
apiVersion: v1
kind: Namespace
metadata:
   name: paas-app-dev2
   labels:
     name: paas-app-dev2