Kubernetes服务部署yaml文件示例

ingress+service+deployment

示例:项目名称devfmintra

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: devfmintra
  name: devfmintra
  namespace: devops
spec:
  replicas: 1 #需要运行的副本数
  revisionHistoryLimit: 5 #要保留以允许回滚的旧副本集的数目
  selector:
    matchLabels:
      app: devfmintra
  strategy:
    rollingUpdate: 
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate #多种升级方案:Recreate:删除所有已存在的pod,重新创建新的; RollingUpdate:滚动升级,逐步替换的策略,同时滚动升级时,支持更多的附加参数,例如设置maxSurge最大不可用pod数量,最小升级间隔时间等等。
  template:
    metadata:
      labels:
        app: devfmintra
    spec:
      terminationGracePeriodSeconds: 60 #k8s将会给应用发送SIGTERM信号,可以用来正确、优雅地关闭应用,默认为30秒
      containers:
      - name: devfmintra
        image: ccr.ccs.tencentyun.com/cloud-ops/fm.intra.ke.com:$BUILD_NUMBER
        imagePullPolicy: Always #拉取策略 默认值,总是拉取 pull;IfNotPresent本地有则使用本地镜像,不拉取;Never只使用本地镜像,从不拉取
        ports:
        - containerPort: 8000
          name: http
          protocol: TCP
        livenessProbe:  #livenessProbe是K8S认为该pod是存活的,不存在则需要kill掉,然后再新启动一个,以达到RS指定的个数。
          httpGet:
            path: /healthcheck
            port: 8000
          initialDelaySeconds: 180
          periodSeconds: 5              #检测间隔时间
          failureThreshold: 2
          timeoutSeconds: 5
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        workingDir: /usr/src/app
        securityContext:
          privileged: false #开启特权模式
        terminationMessagePath: /dev/termination-log
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: qcloudregistrykey
      restartPolicy: Always
      securityContext: {}
      serviceAccountName: ""
      terminationGracePeriodSeconds: 30
      volumes: null
status: {}

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: devfmintra
  name: devfmintra
  namespace: devops
spec:
  ports:
  - name: tcp-8000-80
    port: 80
    protocol: TCP
    targetPort: 8000
  selector:
    app: devfmintra
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
  labels:
    app: devfmintra
  name: devfmintra
  namespace: devops
spec:
  rules:
    - host: fm.intra.dev.ke.com
      http:
        paths:
          - backend:
              serviceName: devfmintra
              servicePort: 80
            path: /
          

X

发表评论

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