# Add a deployment to kuberntese through api

**URL:** <https://discuss.kubernetes.io/t/add-a-deployment-to-kuberntese-through-api/16658>\
**Category:** General Discussions\
**Created:** [July 11, 2021, 11:39am UTC](https://discuss.kubernetes.io/t/add-a-deployment-to-kuberntese-through-api/16658 "2021-07-11T11:39:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmed\_abdalmged](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/ahmed_abdalmged/32/8112_2.png) [@ahmed\_abdalmged](https://discuss.kubernetes.io/u/ahmed_abdalmged)\
**Post date:** [July 11, 2021, 11:39am UTC](https://discuss.kubernetes.io/t/add-a-deployment-to-kuberntese-through-api/16658/1 "2021-07-11T11:39:03Z")

</div>

I am totally new to Kubernetes and what i need to achieve i need to make a call to specific api in my application to add new node to the Kubernetes cluster so i am looking for the best way to do so

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [July 11, 2021, 4:25pm UTC](https://discuss.kubernetes.io/t/add-a-deployment-to-kuberntese-through-api/16658/2 "2021-07-11T16:25:00Z")

</div>

To reach an application that you’ve done via [Deployments](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/), you may want to look into how [Services](https://kubernetes.io/docs/concepts/services-networking/service/) work. A service selects and routes traffic to pods.

---

<div class="post-metadata">

**Author:** ![ahmed\_abdalmged](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/ahmed_abdalmged/32/8112_2.png) [@ahmed\_abdalmged](https://discuss.kubernetes.io/u/ahmed_abdalmged)\
**Post date:** [July 11, 2021, 4:38pm UTC](https://discuss.kubernetes.io/t/add-a-deployment-to-kuberntese-through-api/16658/3 "2021-07-11T16:38:35Z")

</div>

Actually what I really need to have the ability to apply new deployment from an API in web app in docker way I need to start container dynamically when user hit my api

---

<div class="post-metadata">

**Author:** ![protosam](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/protosam/32/7732_2.png) [@protosam](https://discuss.kubernetes.io/u/protosam)\
**Post date:** [July 11, 2021, 6:22pm UTC](https://discuss.kubernetes.io/t/add-a-deployment-to-kuberntese-through-api/16658/4 "2021-07-11T18:22:28Z")

</div>

There’s a few things to unpack to allow your application to create new objects like a Deployment.

- You need to create a `ServiceAccount`
- You need a `ClusterRole` and/or `Role` that defines the access allowed
- You need a `ClusterRoleBinding` and/or `RoleBinding` that attaches the role to the account
- You need to attach the Service account to your pod.

`ClusterRoles` are cluster-wide access while `Roles` are namespaced.

This topic is discussed in the [RBAC](https://kubernetes.io/docs/reference/access-authn-authz/rbac/) and [Configuring Service Accounts for Pods](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/) sections of the documentation (to name a couple). The [Authorization Overview](https://kubernetes.io/docs/reference/access-authn-authz/authorization/) section is also worth a read depending on how in-depth you really want to go on this topic.

As for your application, I would recommend getting to know some of the [Client Libraries](https://kubernetes.io/docs/reference/using-api/client-libraries/).

If you need something example-wise to go off of, I wrote an application in bash that will delete pods to be recreated when configmaps are updated [here](https://github.com/scalabledelivery/conf-reaper). It uses a `ClusterRole`, `ClusterRoleBinding`, and `ServiceAccount`; as well as auto-mounts the API token to the pod. The script itself curls `api-server` via DNS `kubernetes.default.svc.cluster.local`.

I recommend using the client libraries instead of interfacing with the `api-server` directly.

---

<div class="post-metadata">

**Author:** ![ahmed\_abdalmged](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/ahmed_abdalmged/32/8112_2.png) [@ahmed\_abdalmged](https://discuss.kubernetes.io/u/ahmed_abdalmged)\
**Post date:** [July 11, 2021, 8:25pm UTC](https://discuss.kubernetes.io/t/add-a-deployment-to-kuberntese-through-api/16658/5 "2021-07-11T20:25:25Z")

</div>

thank u i really appreciate your help
