k8s cronJob

一、新建.net core 控制台程序:k8scron.job

 二、将发布程序拷贝到服务器:/root/k8swwwroot/k8scron.job

 三、编辑yaml文件k8scron-job-cron.yaml,每分钟执行一次

apiVersion: batch/v1beta1
kind: CronJob
metadata:
 name: k8scron-job-cron
 namespace:  default
 labels:
    name: k8scron-job-cron
spec:
  schedule: "*/1 * * * *"
  suspend: false
  concurrencyPolicy: Forbid 
  startingDeadlineSeconds: 1000  
  jobTemplate:
   spec:
    template:
      metadata:
        labels:
          app: k8scron-job-cron
      spec:
        restartPolicy: OnFailure
        containers:
        - name: k8scron-job-cron
          image: mcr.microsoft.com/dotnet/sdk:6.0
          command: ["/bin/sh"]
          args: ["-c", "echo 'VERSION-20200122175650';cd /mnt/k8scron.job;dotnet k8scron.job.dll"]
          volumeMounts:
          - mountPath: /etc/localtime
            name: volume-localtime
          - mountPath: /mnt/k8scron.job
            name: data
          - mountPath: /mnt/cert
            name: cert
          resources:
            requests:
                memory: "384Mi"
                cpu: "50m"
            limits:
                memory: "1024Mi"
                cpu: "1000m"                                
        volumes:
        - name: volume-localtime
          hostPath:
            path: /etc/localtime
        - name: data
          hostPath:
            path: /root/k8swwwroot/k8scron.job
        - name: cert
          hostPath:
            path: /root/k8swwwroot/cert

四、部属 

kubectl apply -f k8scron-job-cron.yaml 

附:部属为web

apiVersion: apps/v1
kind: Deployment
metadata:
  name: k8scron-job
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: k8scron-job
  template:
    metadata:
      labels:
       app: k8scron-job
    spec:
      containers:
      - name: k8scron-job
        image: mcr.microsoft.com/dotnet/sdk:6.0
        command: ["/bin/sh"]
        args: ["-c", "echo 'VERSION-20200122175650';cd /mnt/k8scron.job;ASPNETCORE_URLS='http://*:5000' dotnet k8scron.job.dll"]
        volumeMounts:
        - mountPath: /mnt/k8scron.job
          name: data
        - mountPath: /mnt/cert
          name: cert
        ports:
        - containerPort: 5000
      volumes:
      - name: data
        hostPath:
          path: /root/k8swwwroot/k8scron.job
      - name: cert
        hostPath:
          path: /root/k8swwwroot/cert
---
apiVersion: v1
kind: Service
metadata:
  name: k8scron-job
  labels: 
   app: k8scron-job
spec:
  type: NodePort
  ports:
  - port: 8002 #k8s内部访问端口
    protocol: TCP
    targetPort: 5000 #.netcore监听端口
    nodePort: 32167 #Node对外固定端口数值
  selector:
    app: k8scron-job

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值