展开

nextflow运行在minikube

最后发布时间 : 2023-12-26 21:59:18 浏览量 :
apiVersion: batch/v1
kind: Job
metadata: &id001
  name: nf-6f7c2991144e63145092136a89314f13
  namespace: nextflow
  labels: {nextflow.io/processName: ccc, nextflow.io/runName: boring_mcnulty, nextflow.io/sessionId: uuid-9cc4e50f-284e-41ff-80a2-75c6c153c57c,
    nextflow.io/app: nextflow, nextflow.io/taskName: ccc_3}
spec:
  backoffLimit: 0
  template:
    metadata: *id001
    spec:
      restartPolicy: Never
      containers:
      - name: nf-6f7c2991144e63145092136a89314f13
        image: quay.io/nextflow/bash
        args: [/bin/bash, -ue, /home/wy/workspace/nf-hello/workDir/6f/7c2991144e63145092136a89314f13/.command.run]
        resources:
          requests: {cpu: 1}
        volumeMounts:
        - {name: vol-2, mountPath: /home/wy/workspace/nf-hello/workDir}
      serviceAccountName: default
      securityContext: {runAsUser: 1000}
      volumes:
      - name: vol-2
        persistentVolumeClaim: {claimName: nextflowdata}

nextflow使用minikube

kubectl create namespace nextflow
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
  namespace: nextflow
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nextflowdata
  namespace: nextflow
spec:
  capacity:
    storage: 2Gi
  volumeMode: Filesystem  # Filesystem(文件系统) Block(块)
  accessModes:
    - ReadWriteMany       # 卷可以被一个节点以读写方式挂载
  persistentVolumeReclaimPolicy: Delete
  storageClassName: local-storage
  local:
    # minikube mount  /home/wy/workspace/nf-hello/workDir:/home/wy/workspace/nf-hello/workDir
    path: /home/wy/workspace/nf-hello/workDir
  nodeAffinity:
    required:
      # 通过 hostname 限定在某个节点创建存储卷
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - minikube

---

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nextflowdata
  namespace: nextflow
spec:
  accessModes: ["ReadWriteMany"]
  storageClassName: "local-storage"
  resources:
    requests:
      storage: 2Gi

生信小木屋

挂载本地路径到minikube容器内

minikube mount  /home/wy/workspace/nf-hello:/home/wy/workspace/nf-hello

nextflow脚本

nextflow.config

process.container = 'quay.io/nextflow/bash'
process.scratch = true


k8s {
    storageClaimName = 'nextflowdata'
    computeResourceType = 'Job'
    storageMountPath = '/home/wy/workspace/nf-hello/workDir'
    // 查看cotext: kubectl config get-contexts
    context = 'minikube' 
}
process {
    executor = 'k8s'
}

main.nf

#!/usr/bin/env nextflow
nextflow.enable.dsl=2 

process sayHello {
  input: 
    val x
  output:
    path("${x}*")
  script:
    """
    sleep 30
    echo '$x world!' > ${x}.txt
    """
}
process catHello {
  input: 
    path x
  output:
    path("${x}*")
  script:
    """
    cat $x  > ${x}.txt
    """
}
println params.input
workflow {
  Channel.of('Bonjour', 'Ciao', 'Hello', 'Hola') | sayHello 
}
nf run main.nf  -w /home/wy/workspace/nf-hello/workDir

使用namespace

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nextflowdata
  namespace: nextflow
k8s {
    storageClaimName = 'nextflowdata'
    computeResourceType = 'Job'
    storageMountPath = '/home/wy/workspace/nf-hello/workDir'
    // 查看cotext: kubectl config get-contexts
    context = 'minikube' 
    //pullPolicy='aa'
    namespace = 'nextflow'
}

不要忘记minikube mount /home/wy/workspace/nf-hello/workDir:/home/wy/workspace/nf-hello/workDir

kubectl describe  pod -n nextflow