gpt4 book ai didi

shell - 如何在Kubernetes中使用Cron Job运行具有ssh命令的Shell脚本

转载 作者:行者123 更新时间:2023-12-02 12:29:05 26 4
gpt4 key购买 nike

我想使用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/*

关于shell - 如何在Kubernetes中使用Cron Job运行具有ssh命令的Shell脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60319820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com