Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90abbcf

Browse files
authored
Merge pull request#14 from partcyborg/jump-pod-template
Support specifying a custom sshjump pod template
2 parentsa06aee1 +24bfc21 commit90abbcf

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ Add `--cleanup-agent` option if you want to kill the created agent at the end of
169169

170170
In addtion, add`--skip-agent` option if you want to skip automatic starting`ssh-agent`. This is actually a case where you already have ssh-agent managed or you want to manually start the agent.
171171

172+
###Customize SSH jump pod
173+
174+
You can customize the sshjump pod created by`kubectl ssh-jump` by setting the`$SSH_JUMP_POD_TEMPLATE` environment variable to the path to a pod template on disk.
175+
176+
However, customized sshjump pods must be named`sshjump` and run in the current namespace or`kubectl ssh-jump` won't be able to find them.
177+
172178
###Examples
173179

174180
Show all node list. Simply executing`kubectl ssh-jump` gives you the list of destination nodes as well as command usage
@@ -209,6 +215,9 @@ Example:
209215
Scenario2 - You have .pem file but you don't have public key on your side
210216
$ kubectl ssh-jump -u ec2-user -i ~/.ssh/mykey.pem hostname
211217
218+
Scenario3 - You want to use a custom sshjump pod definition
219+
$ kubectl ssh-jump -u ec2-user -i ~/.ssh/mykey.pem --pod-template ~/myjumppod.yaml hostname
220+
212221
List of destination node...
213222
Hostname Internal-IP
214223
aks-nodepool1-18558189-0 10.240.0.4

‎kubectl-ssh-jump‎

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Options:
3333
-P, --port <port> SSH port for target node SSH server
3434
Defaults to 22
3535
-a, --args <args> Args to exec in ssh session
36+
--pod-template <file> Path to custom sshjump pod definition
3637
--skip-agent Skip automatically starting SSH agent and adding
3738
SSH Identity key into the agent before SSH login
3839
(=> You need to manage SSH agent by yourself)
@@ -119,19 +120,13 @@ cleanup_agent(){
119120
fi
120121
}
121122

122-
run_ssh_node(){
123-
local destnode="$1"
124-
local sshuser="$2"
125-
local identity="$3"
126-
local pubkey="$4"
127-
local port="$5"
128-
local sshargs="$6"
129-
130-
# Install an SSH Server if not yet installed
131-
r=$(kubectl get pod sshjump2>/dev/null| tail -1| awk'{print $1}')#
132-
if ["${r}"!="sshjump" ];then
133-
echo"Creating SSH jump host (Pod)..."
134-
cat<<EOF | kubectl apply -f -
123+
create_jump_pod(){
124+
local pod_template
125+
if [[-n"${jump_pod_template:-}"&&-e"${jump_pod_template}" ]];then
126+
pod_template=$(<"${jump_pod_template}")
127+
fi
128+
if [[-z"${pod_template}" ]];then
129+
pod_template=$(cat<<EOF
135130
apiVersion: v1
136131
kind: Pod
137132
metadata:
@@ -147,6 +142,24 @@ spec:
147142
nodeSelector:
148143
"kubernetes.io/os": linux
149144
EOF
145+
)
146+
fi
147+
echo"Creating SSH jump host (Pod)..."
148+
echo"${pod_template}"| kubectl apply -f -
149+
}
150+
151+
run_ssh_node(){
152+
local destnode="$1"
153+
local sshuser="$2"
154+
local identity="$3"
155+
local pubkey="$4"
156+
local port="$5"
157+
local sshargs="$6"
158+
159+
# Install an SSH Server if not yet installed
160+
r=$(kubectl get pod sshjump2>/dev/null| tail -1| awk'{print $1}')#
161+
if ["${r}"!="sshjump" ];then
162+
create_jump_pod
150163

151164
# Wait until sshjump gets ready
152165
c=1
@@ -237,6 +250,10 @@ plugin_main() {
237250
sshargs="$2"
238251
nSkip=2
239252
;;
253+
"--pod-template")
254+
jump_pod_template="$2"
255+
nSkip=2
256+
;;
240257
[0-9a-zA-Z-]*)
241258
destnode=$1
242259
;;
@@ -310,6 +327,10 @@ plugin_main() {
310327
echo"using: args=${sshargs}"
311328
fi
312329

330+
if ["${jump_pod_template}"!="" ];then
331+
echo"using: pod-template=${jump_pod_template}"
332+
fi
333+
313334
# Caching current ssh options
314335
write_options"${c_sshuser}""${c_identity}""${c_pubkey}""${c_port}"
315336

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp