deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: ${NAME}  #服务名称
  name: ${NAME}
  namespace: ${NAMESPACE}  #名称空间
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ${NAME}
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: ${NAME}
    spec:
      containers:
      - name: ${NAME}
        image: ${IMAGE}   #镜像地址
        imagePullPolicy: IfNotPresent
        env:
        - name: SERVER_PORT
          value: ${SERVER_PORT}   #服务端口,后端一般8080,前端80
        - name: DEPLOY_ENV
          value: ${DEPLOY_ENV}    #部署环境                  
        ports:
        - name: http
          containerPort: 8080
          protocol: TCP
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /health
            port: 8080
            scheme: HTTP
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 3
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /health
            port: 8080
            scheme: HTTP
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 3
        startupProbe:
          httpGet:
            path: /health
            port: 8080
          failureThreshold: 60
          periodSeconds: 10
          timeoutSeconds: 3
        resources:
          requests:
            cpu: 500m
            memory: 2Gi
          limits:
            cpu: 1000m
            memory:  4Gi
      imagePullSecrets:
      - name: docker-secret   #镜像拉取secret

ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: ${NAME}   #服务名称,和deployment名称一样就行
  namespace: ${NAMESPACE}  #名称空间
spec:
  rules:
  - host: ${INGRESS_HOST}  #域名
    http:
      paths:
      - pathType: Prefix
        path:  /  #路径
        backend:
          service:
            name: ${NAME}
            port:
              number: 8080
  tls:
  - hosts:
      - ${INGRESS_HOST}
    secretName: ${INGRESS_HOST_SECRET}   #域名证书secret

带二级目录的ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: ${NAME}
  namespace: ${NAMESPACE}
spec:
  rules:
  - host: ${INGRESS_HOST}
    http:
      paths:
      - pathType: Prefix
        path:  /${INGRESS_PATH}(/|$)(.*) 
        backend:
          service:
            name: ${NAME}
            port:
              number: 8080
  tls:
  - hosts:
      - ${INGRESS_HOST}
    secretName: ${INGRESS_HOST_SECRET}

svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: ${NAME}
  namespace: ${NAMESPACE}
spec:
  ports:
  - name: http
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: ${NAME}
  type: ClusterIP

hpa.yaml

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: ${NAME}
  namespace: ${NAMESPACE}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ${NAME}
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80
  # - type: Resource
  #   resource:
  #     name: memory
  #     target:
  #       type: Utilization
  #       averageUtilization: 80
#  - type: Object
#    object:
#      metric:
#        name: requests-per-second
#      describedObject:
#        apiVersion: networking.k8s.io/v1beta1
#        kind: Ingress
#        name: main-route
#      current:
#        value: 10k

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据