K8s_Deploy:

  1. 环境变量
  2. ingress暴露
  3. port暴露
  4. requests和limits
  5. host绑定

环境变量

spec.template.spec.containers.env

常量定义,比如灰度环境定义:

         - name: APP_ENV
           value: GRAY

有时需要获取容器的一些信息,参数名自定义,则可参数引用:

     - name: POD_NAME
       valueFrom:
         fieldRef:
           fieldPath: metadata.name
     - name: NODE_NAME
       valueFrom:
         fieldRef:
           fieldPath: spec.nodeName
     - name: POD_NAMESPACE
       valueFrom:
         fieldRef:
           fieldPath: metadata.namespace
     - name: NODE_IP
       valueFrom:
         fieldRef:
           fieldPath: status.hostIP

requests And limits

resources:  
    requests:    
        cpu: "1"
        memory: "2Gi"
   limits:    
        cpu: "2"
        memory: "4Gi"

requests表示必须最小需要配置,limits表示最大可占用配置。
设置limits不设置requests默认,requests和limits一样。
设置requests不设置limits,则资源可在充沛条件下无限扩张,建议设置limits.

Ingress暴露(可通过Rancher配置)

要在原有的配置文件上添加以下信息:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: my-app-name
 namespace: my-namespace
spec:
 rules:
   - host: my-app.ingress.local
     http:
       paths:
         - backend:
             serviceName: my-serviceName
             servicePort: 80
           path: /
---
apiVersion: v1
kind: Service
metadata:
 labels:
   app: my-app-name
 name: my-app-name
 namespace: my-namespace
spec:
 ports:
   - name: http
     port: 80
     protocol: TCP
     targetPort: 8080
 selector:
   app: my-app-name
 type: ClusterIP
---

※注意:“---”要保留用于区分不同部分,my[***]要替换为真实信息

PORT暴露(可通过Rancher配置)

apiVersion: v1
kind: Service
metadata:
 labels:
   app: my-appname
 name: my-appname
 namespace: my-namespace
spec:
 ports:
   - port: 8080
     protocol: TCP
     targetPort: http
     name: http
 selector:
   app: vmagent-k8s
 type: NodePort
---

※注意:“---”要保留用于区分不同部分,my[***]要替换为真实信息

Host绑定

spec:
  template:
   spec:
      hostAliases:
      - hostnames:
        - www.example.local
        ip: 172.00.00.00
posted on 2024-10-07 17:51  zhaoqiang1980  阅读(4)  评论(0编辑  收藏  举报