Last active
August 10, 2024 17:12
-
-
Save avoidik/79cd3836523f93cdee1d3b25c0e54348 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 | |
# | |
curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.43.1/yq_linux_amd64 -o /usr/local/bin/yq | |
chmod +x /usr/local/bin/yq | |
# | |
# get certs from kubeconfig | |
# | |
KEY_DATA="$(yq eval '.users[] | select(.name == "kubernetes-admin") | .user.client-key-data' ~/.kube/config | base64 -d)" | |
CERT_DATA="$(yq eval '.users[] | select(.name == "kubernetes-admin") | .user.client-certificate-data' ~/.kube/config | base64 -d)" | |
CA_DATA="$(yq eval '.clusters[] | select(.name == "kubernetes") | .cluster.certificate-authority-data' ~/.kube/config | base64 -d)" | |
# | |
# 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) \ | |
https://192.168.50.101:6443/api/v1/namespaces/default/pods?fieldManager=kubectl-create | |
# | |
# list pods | |
# | |
curl \ | |
--cacert <(echo "${CA_DATA}") \ | |
--cert <(echo "${CERT_DATA}") \ | |
--key <(echo "${KEY_DATA}") \ | |
-H "Accept: application/json" \ | |
https://192.168.50.101:6443/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" \ | |
https://192.168.50.101:6443/api/v1/namespaces/default/pods/pod |
Author
avoidik
commented
May 18, 2021
curl -k \
-H "Accept: application/json" \
-H "Authorization: Bearer $(aws eks get-token --cluster-name eksworkshop-eksctl | jq -r '.status.token')" \
https://C15918F6AD0190339DC3E37DF96941E4.yl4.eu-west-1.eks.amazonaws.com/api/v1/namespaces/default/pods?limit=5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment