K8S部署简单的工具(以oneforall为例)

本文详细介绍了如何在自己的Kubernetes集群中部署OneForAll,包括使用Docker镜像、配置文件挂载、以及如何通过Job确保资源管理。作者还展示了如何使用NFS进行文件共享和调整Pod的重启策略。
摘要由CSDN通过智能技术生成

OneForAll是一款功能强大的子域收集工具。如何在自己的集群里部署类似的程序呢。

这里用oneforall的原因是oneforall可以使用docker运行,并且可以将结果保存到本地。下面来看看怎么部署。

首先创建自己的k8s集群,这个可以在网上找到教程。

来分析一下oneforall的docker运行方法:

docker pull shmilylty/oneforall
docker run -it --rm -v /home/master/results:/OneForAll/results -v /home/master/OneForAll/config:/OneForAll/config shmilylty/oneforall --target baidu.com run

可以看到是将本地目录与container的目录进行挂载,也就是在使用的时候一定要在宿主机下载oneforall的本地config文件。然后我们来看dockerfile的内容:

FROM python:3.8-alpine3.10
MAINTAINER milktea@vmoe.info

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update && apk --no-cache add git build-base libffi-dev libxml2-dev libxslt-dev libressl-dev
ADD requirements.txt /requirements.txt
RUN pip install uvloop -i https://mirrors.aliyun.com/pypi/simple/
RUN pip install -r /requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
RUN git clone https://github.com/blechschmidt/massdns
WORKDIR /massdns
RUN make 
ADD . /OneForAll/
RUN mv /massdns/bin/massdns /OneForAll/thirdparty/massdns/massdns_linux_x86_64
RUN mkdir /OneForAll/results
WORKDIR /OneForAll/

ENTRYPOINT ["python", "oneforall.py"]

然后可以以此来创建属于我们的pod,下面是yaml:

apiVersion: v1
kind: Pod
metadata:
  name: oneforall-baidu-com
  labels:
    app: oneforall
spec:
  containers:
  - name: oneforall-container
    image: shmilylty/oneforall
    command: 
    args: ["--target", "baidu.com","run"]
    volumeMounts:
    - mountPath: /OneForAll/results
      name: results-volume
    - mountPath: /OneForAll/config shmilylt
      name: config-volume
  volumes:
  - name: results-volume
    hostPath:
      path: /home/master/results
  - name: config-volume
    hostPath:
      path: /home/master/OneForAll/config

这里用的是hostpath方法进行文件挂载,实际需要可以使用其他文件共享方式,比如后面我使用了nfs进行文件共享。

然后我们就可以得到一个成功运行的pod。

但是我们会找到一个问题,pod是一直运行的,要是集群重启那就会再次运行占用资源,这里我们用job来解决,job是调用一次pod,运行成功就将pod解决掉。

apiVersion: batch/v1
kind: Job
metadata:
  name: one
spec:
  backoffLimit: 4 # 可选:设置失败重试次数(默认为6次)
  template:
    metadata:
      name: one
      labels:
        app: oneforall
    spec:
      containers:
      - name: oneforall
        image: shmilylty/oneforall
        command:
        args: ["--target", "example.com", "run"]
        workingDir: /OneForAll
        securityContext: # 在此处添加容器级别的 securityContext
          privileged: true
        volumeMounts:
        - mountPath: /OneForAll/results
          name: results-volume
        - mountPath: /OneForAll/config shmilylty
          name: config-volume
      volumes:
      - name: results-volume
        nfs:
          server: 192.168.101.137
          path: /home/master/nfs/lankao_res
      - name: config-volume
        hostPath:
          path: /home/master/OneForAll/config
      restartPolicy: Never # 必须设置为 "Never",因为 Job 中的 Pod 不应自动重启

下面是扫描的结果:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值