Skip to content

Instantly share code, notes, and snippets.

@lkoba
Created December 20, 2019 19:05
Show Gist options
  • Save lkoba/e73dcc13bd8d81907b1f4069a19979ec to your computer and use it in GitHub Desktop.
Save lkoba/e73dcc13bd8d81907b1f4069a19979ec to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eo pipefail
json=`cat $1 | y2j`
overrides=`echo "$json" | jq "{spec}"`
name=`echo "$json" | jq -r ".metadata.name"`
labels=`echo "$json" | jq -r '.metadata.labels | keys[] as $k | "\($k)=\(.[$k])"' | paste -sd "," -`
image=`echo "$json" | jq -r ".spec.containers[0].image"`
shift
kubectl run "$name" -it --rm --image="$image" --labels="$labels" --restart=Never --overrides="$overrides" "$@"
@adamency
Copy link

Good and simple workaround solution until kubectl provides the ability (which will most likely be never...) to run kubernetes pod manifests interactively.

However, beware as this does not take into account:

  • volumes
  • env vars
  • command override
  • args

A lot of parsing is still needed to actually correctly convert a usual pod manifest into a kubectl run command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment