首页 > 解决方案 > 带有堡垒和自定义 SSH 端口 + 代理转发的 Kubespray

问题描述

是否可以将 Kubespray 与 Bastion 一起使用,但可以在自定义端口和代理转发上使用?如果不支持,需要进行哪些更改?

标签: sshkuberneteskubespray

解决方案


始终,因为您可以在三个不同的级别进行配置:通过主机用户的~/.ssh/config,通过带有 的整个剧本group_vars,或作为内联配置(即在命令行或库存文件中)。

ssh 配置希望很简单:

Host 1.2.* *.example.com # or whatever pattern matches the target instances
  ProxyJump someuser@some-bastion:1234
  # and then the Agent should happen automatically, unless you mean
  # ForwardAgent yes

接下来我将讨论内联配置,因为它更简单一些:

ansible-playbook -i whatever \
    -e '{"ansible_ssh_common_args": "-o ProxyJump=\"someuser@jump-host:1234\""}' \
    cluster.yaml

或以相同的方式通过库存:

master-host-0 ansible_host=1.2.3.4 ansible_ssh_common_args="-o ProxyJump='someuser@jump-host:1234'"

或 via group_vars,您可以将其添加到现有的group_vars/all.yml,或者如果它不存在,则创建group_vars包含该all.yml文件的目录作为包含您的库存文件的目录的子目录

如果您的 ssh 配置比您希望在 inventory/command-line/group_vars 中编码更复杂,您还可以通过ansible_ssh_extra_args变量指示 ansible-invoked ssh 使用专用配置文件:

ansible-playbook -e '{"ansible_ssh_extra_args": "-F /path/to/special/ssh_config"}' ...

推荐阅读