【问题标题】:How to run Shell script having ssh commands using cron job in kubernetes如何在 kubernetes 中使用 cron 作业运行具有 ssh 命令的 Shell 脚本
【发布时间】:2020-06-04 18:31:30
【问题描述】:

我想使用 kubernetes 中的 cron 作业运行在文件中有 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 消息。

谁能帮我解决这个问题。

【问题讨论】:

  • 请检查您的 pod 中是否安装了 ssh 实用程序,以及您是否有权创建 kube 作业。如果没有,请为您的用户更改角色或集群角色。
  • 请按照@anmolagrawal 的建议告诉我们。如果您有任何问题,请不要犹豫。
  • 您的意思是我们需要在 docker 中安装 ssh 实用程序吗?我们可以在 pod 中使用它们吗?你能指导我如何从 linux 服务器在 docker 中安装 ssh..

标签: shell kubernetes ssh cron


【解决方案1】:

此消息 (ssh command not found) 表明您的 pod 中缺少 ssh 客户端。在 cmets 中,您提到了 docker,所以我假设您正在使用您的 docker 映像。

要在您的 docker 容器中安装 SSH,您必须根据我们的 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/*

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 2019-04-22
    • 2011-04-25
    • 2016-11-07
    • 1970-01-01
    相关资源
    最近更新 更多