Simple walkthrough of Kubernetes API
You can also execute the shell script to perform these steps.
Install JQ before trying the commands. Make sure that you have access to a Kubernetes cluster.
kubectl cluster-info
kubectl component-status
kubectl proxy --port=8000&
open http://localhost:8000/swagger-ui/
curl http://localhost:8000/api
curl -s http://localhost:8000/api/v1/nodes | jq '.items[] .metadata.labels'
cat > nginx-pod.json <<EOF
{
"kind": "Pod",
"apiVersion": "v1",
"metadata":{
"name": "nginx",
"namespace": "default",
"labels": {
"name": "nginx"
}
},
"spec": {
"containers": [{
"name": "nginx",
"image": "nginx",
"ports": [{"containerPort": 80}],
"resources": {
"limits": {
"memory": "128Mi",
"cpu": "500m"
}
}
}]
}
}
EOF
cat > nginx-service.json <<EOF
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "nginx-service",
"namespace": "default",
"labels": {"name": "nginx"}
},
"spec": {
"ports": [{"port": 80}],
"selector": {"name": "nginx"}
}
}
EOF
curl -s http://localhost:8000/api/v1/namespaces/default/pods \
-XPOST -H 'Content-Type: application/json' \
[email protected] \
| jq '.status'
curl -s http://localhost:8000/api/v1/namespaces/default/services \
-XPOST -H 'Content-Type: application/json' \
[email protected] \
| jq '.spec.clusterIP'
kubectl get pods
kubectl get svc
curl http://localhost:8000/v1/proxy/namespaces/default/services/nginx-service/
curl http://localhost:8000/api/v1/namespaces/default/services/nginx-service -XDELETE
curl http://localhost:8000/api/v1/namespaces/default/pods/nginx -XDELETE