其他分享
首页 > 其他分享> > kubenetes的deployment模板

kubenetes的deployment模板

作者:互联网

apiVersion: apps/v1 
kind: Deployment 
metadata: 
  name: deploy-service # deployment名称 
  namespace: test
  annotations: 
    kubernetes.io/change-cause: "1.0" # 版本说明 - 用于回滚等 
spec: 
  selector: 
    matchLabels: 
      app: deploy-service # 标签选择器,与下面[Flag_label]对应 
  replicas: 3 # 多实例 
  template: 
    metadata: 
      labels: 
        app: deploy-service # [Flag_label] 
    spec: 
      #构建初始化镜像(通过初始化镜像的方式集成SkyWalking Agent)
      initContainers: 
        - image: harbor.test.com/public/sky-agent:8.8.0
          name: sw-agent-sidecar
          imagePullPolicy: IfNotPresent
          command: [ "sh" ]
          args: ['-c','mkdir -p /skywalking/agent && cp -r /usr/skywalking/agent/* /skywalking/agent']
          volumeMounts:
            - mountPath: /skywalking/agent
              name: sw-agent
      imagePullSecrets: 
        - name: regsecret
      containers: 
        - name: deploy-service # EFK日志系统日志查询tag 
          image: deploy-image # 镜像地址:版本 
          imagePullPolicy: IfNotPresent 
          ports: 
            - containerPort: serverport # 服务暴露端口 
          resources: # 服务所需资源申请 
            requests: 
              memory: "2Gi" 
              cpu: "1" 
            limits: 
              memory: "2Gi" 
              cpu: "1" 
          env: # 环境变量 
            - name: MY_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
             #这里通过JAVA_TOOL_OPTIONS,而不是JAVA_OPTS可以实现不通过将agent命令加入到java应用jvm参数而实现agent的集成
            - name: JAVA_TOOL_OPTIONS
              value: -javaagent:/usr/skywalking/agent/skywalking-agent.jar
            - name: SW_AGENT_NAME
              value: dev-gateway-demo
            - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
              value: 192.168.1.2:11800 #sky server端地址
              #value: skywalking-oap.default.svc:11800
            - name: SW_AGENT_INSTANCE_NAME
              value: dev_$(MY_POD_NAME)
            - name: java_opts 
              value: "-Dspring.profiles.active=dev -Dspring.cloud.nacos.server-addr=nacos:8848" 
            - name: jvm_opts
              value: "-Xms2g -Xmx2g" 
            # - name: sky_agent_id
            #   value: "-Dskywalking.agent.instance_name=test_$(MY_POD_NAME) -DSW_AGENT_NAME=k8s_deploy-service" 
          livenessProbe: # 存活探针 
            httpGet: 
              path: /actuator/health 
              port: serverport
            initialDelaySeconds: 150
            periodSeconds: 10 
            timeoutSeconds: 5 
          readinessProbe: # 就绪探针 
            httpGet: 
              path: /actuator/health 
              port: serverport 
            initialDelaySeconds: 100 
            periodSeconds: 5
            timeoutSeconds: 5 
          lifecycle: 
            preStop: # pod停止前Hook - 优雅停机 
              exec: 
                command: 
                  - "curl" 
                  - "-XPOST" 
                  - "http://127.0.0.1:serverport/actuator/shutdown" 
          volumeMounts: 
            - mountPath: /usr/skywalking/
              name: sw-agent
      volumes:
        - name: sw-agent
          emptyDir: { }
--- 
apiVersion: v1 
kind: Service 
metadata: 
  name: deploy-service # 服务名称 
  namespace: test
  #annotations: 
  #  prometheus.io/path: /actuator/prometheus # 应用监控metrics路径 - 对应配置文件开启prometheus 
  #  prometheus.io/port: "serverport" 
  #  prometheus.io/scrape: "true" 
  labels: 
    app: deploy-service
spec: 
  type: ClusterIP 
  ports: 
    - port: serverport 
      targetPort: serverport 
  selector: 
    app: deploy-service 
--- 
# 请根据实际情况,选择是否需要对外暴露Ingress 
## 在微服务架构中,一般通过Gateway网关统一对外提供服务,微服务单独对外暴露Ingress情况请谨慎选择 
apiVersion: networking.k8s.io/v1
kind: Ingress 
metadata: 
  name: deploy-service 
  namespace: test
  annotations: 
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/load-balance: "ip_hash" # session保持 
    nginx.ingress.kubernetes.io/upstream-hash-by: "$request_uri" # 配合ip_hash使用 
spec: 
  rules: 
    - host: deploy-service.ingress.com # Ingress 域名 
      http: 
        paths: 
          - path: / 
            pathType: Prefix
            backend: 
              service: 
                name: deploy-service 
                port: 
                  number: serverport

标签:name,service,deploy,agent,kubenetes,io,deployment,skywalking,模板
来源: https://www.cnblogs.com/pgy674477230/p/16350982.html