Kubernetes REST API - Create deployment

9/9/2016

I was looking at the kubernetes API endpoints listed here. Im trying to create a deployment which can be run from the terminal using kubectl ru CLUSTER-NAME IMAGE-NAME PORT. However I cant seem to find any endpoint for this command in the link I posted above. I can create a node using curl POST /api/v1/namespaces/{namespace}/pods and then delete using the curl -X DELETE http://localhost:8080/api/v1/namespaces/default/pods/node-name where node name HAS to be a single node (if there are 100 nodes, each should be done individually). Is there an api endpoint for creating and deleting deployments??

-- Beginner
kubernetes

5 Answers

2/11/2017

To make it easier to eliminate fields or restructure resource representations, Kubernetes supports multiple API versions, each at a different API path, such as /api/v1 or /apis/extensions/v1beta1 and to extend the Kubernetes API, API groups is implemented.

Currently there are several API groups in use:

  • the core (oftentimes called legacy, due to not having explicit group name) group, which is at REST path /api/v1 and is not specified as part of the apiVersion field, e.g. apiVersion: v1.
  • the named groups are at REST path /apis/$GROUP_NAME/$VERSION, and use apiVersion: $GROUP_NAME/$VERSION (e.g. apiVersion: batch/v1). Full list of supported API groups can be seen in Kubernetes API reference.

To manage extensions resources such as Ingress, Deployments, and ReplicaSets refer to Extensions API reference.

As described in the reference, to create a Deployment:

POST /apis/extensions/v1beta1/namespaces/{namespace}/deployments

-- Kamran
Source: StackOverflow

12/30/2016

I debugged this by running kubectl with verbose logging: kubectl --v=9 update -f dev_inventory.yaml.

It showed the use of an API call like this one:

curl -i http://localhost:8001/apis/extensions/v1beta1/namespaces/default/deployments

Note that the first path element is apis, not the normal api. I don't know why it's like this, but the command above works.

-- kgilpin
Source: StackOverflow

10/7/2016

The Kubernetes Rest Api documentation is quite sophisticated but unfortunately the deployment documentation is missing. Since the Rest schema is identical to other resources you can figure out the rest calls:

GET retrieve a deployment by name:

  • curl -H "Authorization: Bearer ${KEY}" ${API_URL}/apis/extensions/v1beta1/namespaces/${namespace}/deployments/${NAME}

POST create a new deployment

  • curl -X POST -d @deployment-definition.json -H "Content-Type: application/json" -H "Authorization: Bearer ${KEY}" ${API_URL}/apis/extensions/v1beta1/namespaces/${namespace}/deployments

You should be able to use the calls right away when you provide the placeholder for your

  • API key ${KEY}
  • API url ${API_URL}
  • Deployment name ${NAME}
  • Namespace ${namespace}
-- Endian Ogino
Source: StackOverflow

3/30/2018

I might be too late to help in this question, but here is what I tried on v1.9 to deploy a StatefulSet:

curl -kL -XPOST -H "Accept: application/json" -H "Content-Type: application/json" \
 -H "Authorization: Bearer <*token*>" --data @statefulset.json \
 https://<*ip*>:6443/apis/apps/v1/namespaces/eng-pst/statefulsets

I converted the statefulset.yaml to json cause I saw the data format when api was doing the POST was in json.

I ran this command to find out the API call i need to make for my k8s object:

kubectl --v=10 apply -f statefulset.yaml

(might not need a v=10 level but I wanted to as much info as I could)

-- Skotu
Source: StackOverflow

9/9/2016

Have you tried the analogous URL?

http://localhost:8080/api/v1/namespaces/default/deployment/deployment-name
-- ffledgling
Source: StackOverflow