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 不应自动重启
下面是扫描的结果: