-
-
Save tuxerrante/346834e64e43aead01605e14cf2df4e8 to your computer and use it in GitHub Desktop.
Use curl instead of kubectl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### | |
# download yq | |
# | |
set -ex | |
# https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release | |
latest_tag=$(curl -sL -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/mikefarah/yq/releases/latest |jq -r .tag_name) | |
curl -fsSL https://github.com/mikefarah/yq/releases/download/${latest_tag}/yq_linux_amd64 -O | |
yq_linux_amd64_checksum="$(curl -fsSL https://github.com/mikefarah/yq/releases/download/${latest_tag}/checksums |grep "yq_linux_amd64 " |tr --squeeze-repeats [:space:] |cut -d' ' -f2- )" | |
grep "$(sha256sum yq_linux_amd64 |cut -d' ' -f1)" yq_linux_amd64_checksum || echo "WARNING: SHA256 not found!" | |
mv yq_linux_amd64 yq | |
chmod +x yq | |
sudo mv yq /usr/local/bin/yq | |
yq --version | |
### | |
# get certs from kubeconfig | |
# | |
# Input Args | |
CLUSTER_USER=$1 | |
CLUSTER_NAME=$2 | |
KEY_DATA="$( yq eval '.users[] | select(.name == env(CLUSTER_USER)) | .user.client-key-data' $KUBECONFIG |base64 -d --wrap=76)" | |
CERT_DATA="$(yq eval '.users[] | select(.name == env(CLUSTER_USER)) | .user.client-certificate-data' $KUBECONFIG | base64 -d --wrap=76)" | |
CA_DATA="$( yq eval '.clusters[] | select(.name == env(CLUSTER_NAME)) | .cluster.certificate-authority-data' $KUBECONFIG | base64 -d --wrap=76)" | |
SERVER="$(yq eval '.clusters[] | select(.name == env(CLUSTER_NAME)) | .cluster.server' $KUBECONFIG)" | |
# | |
# deploy pod | |
# | |
#curl -X POST \ | |
# --cacert <(echo "${CA_DATA}") \ | |
# --cert <(echo "${CERT_DATA}") \ | |
# --key <(echo "${KEY_DATA}") \ | |
# -H "Content-Type: application/json" \ | |
# -H "Accept: application/json" \ | |
# --data-binary @<(yq eval -j pod.yaml) \ | |
# ${SERVER}/api/v1/namespaces/default/pods?fieldManager=kubectl-create | |
# See resources names | |
curl \ | |
--cacert <(echo "${CA_DATA}") \ | |
--cert <(echo "${CERT_DATA}") \ | |
--key <(echo "${KEY_DATA}") \ | |
-H "Accept: application/json" \ | |
${SERVER}/api/v1 |jq .resources[].name | |
# | |
# list pods | |
# | |
curl \ | |
--cacert <(echo "${CA_DATA}") \ | |
--cert <(echo "${CERT_DATA}") \ | |
--key <(echo "${KEY_DATA}") \ | |
-H "Accept: application/json" \ | |
${SERVER}/api/v1/namespaces/default/pods?limit=5 | |
# | |
# delete pod | |
# | |
curl -X DELETE \ | |
--cacert <(echo "${CA_DATA}") \ | |
--cert <(echo "${CERT_DATA}") \ | |
--key <(echo "${KEY_DATA}") \ | |
-H "Accept: application/json" \ | |
-H "Content-Type: application/json" \ | |
${SERVER}/api/v1/namespaces/default/pods/test_pod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment