我想使用kubernetes中的cron job运行在文件中包含ssh命令的shell脚本
test.sh
#!/bin/bash
echo copying files from edge node to batch pods;
ssh -q userid@<hostname>"kubectl config use-context testnamespace";
ssh -q userid@<hostname>"kubectl scale statefulsets testpod --replicas=1";
当我通过pod手动执行它时,它会抛出错误"ssh command not found"
并触发作业向我抛出permission denied
消息。
谁能帮助我解决这个问题。
此消息(ssh command not found
)表示您的Pod中缺少ssh客户端。在评论中,您提到的是docker,所以我假设您正在使用docker映像。
要将SSH安装到您的Docker容器中,您必须根据我们的Linux发行版运行apt-get或yum或任何其他软件包管理器,并且这需要在您的Dockerfile中表达。
这是如何实现此目的的示例:
# A basic apache server. To use either add or bind mount content under /var/www
FROM ubuntu:12.04
MAINTAINER Kimbro Staken version: 0.1
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
在此示例中,我们在ubuntu映像上安装apache。在您的方案中,您需要运行类似于以下内容的代码:
RUN apt-get update && apt-get install -y openssh-client && apt-get clean && rm -rf /var/lib/apt/lists/*
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句