Skip to content

Latest commit

 

History

History
73 lines (59 loc) · 2.05 KB

008.md

File metadata and controls

73 lines (59 loc) · 2.05 KB

Day 8

Agenda

  1. https://www.safaribooksonline.com/library/view/kubernetes-fundamentals/9781492032144/
    • Using curl to discover the API resources (05:15 mins)
    • Understanding namespaces (06:42 mins)
    • Defining quotas (04:01 mins)
  2. Using httpie and jq

Notes

Using httpie and jq

Using httpie and jq work with Kubernetes REST API

$ minikube version
minikube version: v0.25.0

$ minikube start

// Start proxy to "get authorized"
$ kubectl proxy
Starting to serve on 127.0.0.1:8001

// List the namespaces
$ http localhost:8001/api/v1/namespaces | jq -r '.items[].metadata.name'
default
kube-public
kube-system

// -v=9 to debug the connection
// and learn the Request Body and the URL
$ kubectl -v=9 create ns jacek
...
Request Body: {"kind":"Namespace","apiVersion":"v1","metadata":{"name":"jacek","creationTimestamp":null},"spec":{},"status":{}}
...
curl -k -v -XPOST  -H "Content-Type: application/json" -H "User-Agent: kubectl/v1.9.3 (darwin/amd64) kubernetes/d283541" -H "Accept: application/json, */*" https://192.168.99.100:8443/api/v1/namespaces
...
Response Body: {"kind":"Namespace","apiVersion":"v1","metadata":{"name":"jacek","selfLink":"/api/v1/namespaces/jacek","uid":"3c998908-128f-11e8-a9dd-080027beab3f","resourceVersion":"133410","creationTimestamp":"2018-02-15T20:31:44Z"},"spec":{"finalizers":["kubernetes"]},"status":{"phase":"Active"}}
namespace "jacek" created

// Let's simulate kubectl create ns sandbox
// Create a JSON file
// Find it as namespace-sandbox.json
// BEGIN
{
  "kind": "Namespace",
  "apiVersion": "v1",
  "metadata": {
    "name": "sandbox"
  }
}
// END

$ http POST localhost:8001/api/v1/namespaces @namespace-sandbox.json
HTTP/1.1 201 Created
Content-Length: 289
Content-Type: application/json
Date: Thu, 15 Feb 2018 20:39:26 GMT
...

$ kubectl get ns
NAME          STATUS    AGE
default       Active    23d
jacek         Active    8m
kube-public   Active    23d
kube-system   Active    23d
sandbox       Active    38s

$ minikube stop