k8s简单服务模板

时间:2020-05-18
本文章向大家介绍k8s简单服务模板,主要包括k8s简单服务模板使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

一个简单的服务模板

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tophc-link-portal
  namespace: prod
spec:
  selector:
    matchLabels:
      app: tophc-link-portal
  replicas: 3
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: tophc-link-portal
    spec:
      imagePullSecrets:
      - name: tophc-harbor
      containers:
      - name: tophc-link-portal
        env:
        - name: springProfiles
          value: prod
        - name: TZ
          value: CST-8
        image: xxxx-link-portal:latest
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 80
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 2
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 80
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 3
          successThreshold: 1
          timeoutSeconds: 2
        ports:
          - containerPort: 80
        resources:
          limits:
            cpu: 300m
            memory: 200Mi
          requests:
            cpu: 200m
            memory: 100Mi
            
---

# 自动扩缩容

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: tophc-link-portal-hpa-v2
  namespace: prod
spec:
  minReplicas: 2
  maxReplicas: 6
  scaleTargetRef:
    apiVersion: extensions/v1beta1
    kind: Deployment
    name: tophc-link-portal
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 70
  - type: Resource
    resource:
      name: memory
      targetAverageUtilization: 70
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: tophc-link-portal
  name: tophc-link-portal
  namespace: prod
spec:
  ports:
  - name: http
    port: 80
    targetPort: 80
  selector:
    app: tophc-link-portal
  type: ClusterIP

---

# 服务暴露

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  labels:
    env: prod
    project: tophc
    service: tophc-link-portal
  name: tophc-link-portal-80
  namespace: prod
spec:
  rules:
  - host: portal.xxxxxxx.xxx
    http:
      paths:
      - backend:
          serviceName: tophc-link-portal
          servicePort: 80
        path: /

原文地址:https://www.cnblogs.com/lizhaojun-ops/p/12910768.html