Skip to content

Instantly share code, notes, and snippets.

@avoidik
Last active April 30, 2024 06:54
Show Gist options
  • Save avoidik/79cd3836523f93cdee1d3b25c0e54348 to your computer and use it in GitHub Desktop.
Save avoidik/79cd3836523f93cdee1d3b25c0e54348 to your computer and use it in GitHub Desktop.
Use curl instead of kubectl
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment