curl -s -k \
--cert ~/.minikube/client.p12 \
--key ~/.minikube/client.key \
--pass tcuser \
https://192.168.64.8:8443/api/v1/pods \
|jq '.items[].metadata.name'
k8s() { path=${1:? k8s api path required}; [[ "$DEBUG" ]] && set -x; shift ; curl -s -k --cert ~/.minikube/client.p12 --key ~/.minikube/client.key --pass tcuser https://192.168.64.8:8443/${path#/} "$@"; set +x; }
To be able to use curl agains k8s API you need certs and keys, in appropriate format.
First install a yaml2json converter:
go get -v github.com/bronze1man/yaml2json
Then extract the client cert and key:
yaml2json < ~/.kube/config | jq '.users[]|select(.name=="docker-for-desktop")|.user["client-certificate-data"]' -r | base64 -D > cli.cert
yaml2json < ~/.kube/config | jq '.users[]|select(.name=="docker-for-desktop")|.user["client-key-data"]' -r | base64 -D > cli.key
Convert the cert and key into pkcs12 format:
openssl pkcs12 -export -in cli.cert -inkey cli.key -out cli.p12 -password pass:tcuser
Finally you can use curl against k8s API. List pods from all namespaces:
curl -k --cert cli.p12 --key cli.key --pass tcuser https://127.0.0.1:6443/api/v1/pods
only pod ns and names:
curl -s -k --cert cli.p12 --key cli.key --pass tcuser https://127.0.0.1:6443/api/v1/pods| jq '.items[].metadata|[.namespace,.name]' -c
list all resourcetypes"
curl -s -k --cert cli.p12 --key cli.key --pass tcuser https://127.0.0.1:6443/api/v1|jq '.resources[].name'
delete a pod:
curl -k --cert cli.p12 --key cli.key --pass tcuser -XDELETE https://localhost:6443/api/v1/namespaces/default/pods/firstpod