在 Kubernetes 上部署 Python 3.7、Chrome 和 Chromedriver(版本 114.0.5735.90)的完整指南

一、构建基础镜像

bash 复制代码
docker build -f /u01/isi/DockerFile . -t  thinking_code.com/xhh/crawler_base_image:v1.0.2

docker push thinking_code.com/xhh/crawler_base_image:v1.0.2

二、K8s运行Pod

三、DockerFile文件

bash 复制代码
# 基于镜像基础
FROM python:3.7

# 设置代码文件夹工作目录 /app
WORKDIR /app
# 复制当前代码文件到容器中 /app
ADD . /app

# 安装常用命令
RUN apt-get update && apt-get install -y \
    coreutils \
    vim \
    wget \
    curl \
    net-tools \
    iputils-ping \
    telnet \
    curl \
    cron \
    gnupg \
    && curl -fsSL https://deb.nodesource.com/setup_current.x | bash - \
    && apt-get install -y nodejs \
    && apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# 安装插件库
RUN pip install pyyaml
RUN pip install selenium
RUN pip install pycryptodome

# 安装所需的包
RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt

# 安装 wget 和其他必要工具(如果没有 wget 的话)
RUN apt-get update && apt-get install -y wget unzip
# 将 Chrome 安装文件复制到 Docker 镜像中(假设文件在当前目录下)
COPY google-chrome-stable_114.0.5735.90-1_amd64.deb /tmp/google-chrome.deb
# 安装 Google Chrome
RUN apt-get install -y /tmp/google-chrome.deb
# 查看安装的 Google Chrome 版本
RUN google-chrome --version

# 安装 ChromeDriver(假设已经将 chromedriver.zip 复制到 Docker 镜像中)
COPY chromedriver.zip /tmp/chromedriver.zip
RUN unzip /tmp/chromedriver.zip -d /usr/local/bin/ && chmod +x /usr/local/bin/chromedriver

四、依赖文件

requirements.txt

复制代码
Jsonpath==0.82
Requests==2.31.0
loguru==0.6.0
lxml==4.9.2
nodejs==0.1.1
PyExecJS==1.5.1
PyMySQL==1.0.3
pyquery==2.0.0
redis==4.5.4
urllib3==1.25.11
Flask==2.2.5
dateparser==1.1.8
kafka-python==2.0.2
python-dateutil==2.8.2
retrying==1.3.4
elasticsearch==7.13.0
pycryptodome==3.19.0
requests-toolbelt==1.0.0

五、参考网址

Debian 中文软件仓库

相关推荐
scugxl22 分钟前
centos7 docker离线安装
运维·docker·容器
绿箭柠檬茶2 小时前
Ubuntu 使用 Samba 共享文件夹
linux·运维·ubuntu
工藤新一¹3 小时前
Linux —— 虚拟进程地址空间
linux·运维·服务器·c/c++·虚拟进程地址空间
Aspiresky3 小时前
浅析Linux内核scatter-gather list实现
linux·dma·scatter/gather
奔跑吧 android4 小时前
【linux kernel 常用数据结构和设计模式】【数据结构 3】【模拟input子系统input_dev和input_handler之间的多对多关系】
linux·数据结构·input·kernel·input_dev·input_handler·input_handle
再难也得平4 小时前
Linux初级篇
linux·运维·服务器
小猫挖掘机(绝版)5 小时前
通过tailscale实现一台电脑上vscode通过ssh连接另一台电脑上的VMware Linux 虚拟机
linux·windows·vscode·ubuntu·ssh
attitude.x5 小时前
Swift 协议扩展与泛型:构建灵活、可维护的代码的艺术
运维·服务器·网络
ajassi20005 小时前
开源 C++ QT Widget 开发(十三)IPC通讯--本地套接字 (Local Socket)
linux·c++·qt·开源
止观止5 小时前
GitHub自动化利器:Probot框架实战指南
运维·自动化·github