如何在kubernetes中使用cron作业运行包含ssh命令的Shell脚本

如何在kubernetes中使用cron作业运行包含ssh命令的Shell脚本,shell,kubernetes,ssh,cron,Shell,Kubernetes,Ssh,Cron,我想运行shell脚本,该脚本在kubernetes中使用cron作业在文件中包含ssh命令 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 t

我想运行shell脚本,该脚本在kubernetes中使用cron作业在文件中包含ssh命令

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";
#/bin/bash
echo将文件从边缘节点复制到批处理吊舱;
ssh-q userid@“kubectl config use context testnamespace”;
ssh-q userid@“kubectl scale statefulsets testpod--replications=1”;
当我通过pod手动执行它时,它会抛出错误
“ssh command not found”
,并触发作业抛出权限被拒绝的消息

有人能帮我解决这个问题吗。

此消息(
ssh命令未找到
)表示pod中缺少ssh客户端。在评论中,您提到了docker,因此我假设您使用的是docker图像

要在docker容器中安装SSH,必须根据我们的Linux发行版运行apt get或yum或任何其他软件包管理器,这需要在docker文件中表示

以下是如何实现这一目标的示例:

# 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/*
此消息(
ssh命令未找到
)表示pod中缺少ssh客户端。在评论中,您提到了docker,因此我假设您使用的是docker图像

要在docker容器中安装SSH,必须根据我们的Linux发行版运行apt get或yum或任何其他软件包管理器,这需要在docker文件中表示

以下是如何实现这一目标的示例:

# 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/*

请检查pod中是否安装了
ssh
实用程序,以及您是否有创建kube作业的权限。。如果没有,请更改您用户的角色或clusterrole。请按照@anmolagrawal sugestions进行操作,并告知我们。如果您有任何问题,请毫不犹豫地询问。您的意思是我们需要在docker中安装ssh实用程序吗?我们可以在吊舱里用吗?你能告诉我如何从linux服务器在docker中安装ssh吗?请检查你的pod中是否安装了
ssh
实用程序,以及你是否有创建kube作业的权限。。如果没有,请更改您用户的角色或clusterrole。请按照@anmolagrawal sugestions进行操作,并告知我们。如果您有任何问题,请毫不犹豫地询问。您的意思是我们需要在docker中安装ssh实用程序吗?我们可以在吊舱里用吗?你能指导我如何从linux服务器在docker中安装ssh吗。。