---
# System prepended metadata

title: Kapp - A great CLI Tool for Applying K8s resources
tags: [kapp]

---

# Kapp - A great CLI Tool for Applying K8s resources 
### Or 
# Kapp - An application paradigm
### Or 
# Getting started
###### tags: `kapp`

**Pending: If we go for Kapp - An application paradigm, What does application part/paradigm means?**

Kapp is a CLI tool which does more than just applying changes to the Kubernetes cluster. Also, it can work with standard yaml files and other tools like ([ytt](https://carvel.dev/ytt/), [helm](https://helm.sh/) etc.) out of the box. It enriches the applying behavior of kubernetes resources by providing these additional capabilities:
 
1. Calculate and show changes before applying.
2. Wait for K8s resources to be in desired state before exiting successfully.
3. List all the resources(across namespace) owned by an app.

Let's complete the pre-requisite before talking about the above points in depth.

## Prerequisite

* A Kubernetes cluster (preferably Minikube as it better fits local development; Docker for Mac/Linux is another good option as it now includes Kubernetes)
* Check that the cluster works via `kubectl get nodes`
* Install kapp :

    `wget -O- https://carvel.dev/kapp-install-katacoda.sh | bash`

## 1. Calculate and show changes before applying.

Kapp calculate the changes by comparing the new resources(provided in configuration file) with already existing resources( present in the cluster) and provides a summary to the user before applying. This helps the user to visually understand how the cluster will be impacted. With the help of kapp, users can be more confident about the changes.

Let's see this with the help of an example:


1. We will deploy a yaml file consisting of a deployment and service.
    
    `kapp deploy -a simple-app -f ./examples/simple-app-example/config-1.yml`
    
    We are passing two command line arguments to the kapp command. `-a` to specify the name of our application, it can be any valid name. `-f` describes the location of yaml which contains the Kubernetes resources.
    
    ![](https://i.imgur.com/E9pxyys.png)

    Initially the Kubernetes cluster didn't have any resources, hence we see that above deploy command will create a deployment and service.
    
2. Now, lets make a change to the deployment in yaml file. e.g. Let's change the value from "stranger" to "Stranger" and save the file.

3. Let's try to redeploy the file again using kapp.
    
    `kapp deploy -a simple-app -f ./examples/simple-app-example/config-1.yml`
    
    ![](https://i.imgur.com/IYqS6dC.png)
    
    Since there was only a change in the deployment, we can see that kapp will only update the deployment and it won't touch the service.

	

## 2. Wait for K8s resources to be in desired state before exiting successfully

In kapp, Desired states are defined as final state a resource should be in. e.g. for a Pod desired state is Ready state, for a Service desired state is when ip's get set on clusterIP or loadbalancerIngress. More information on desired state for different resources can be found [here](https://carvel.dev/kapp/docs/latest/apply-waiting/#overview). 

By waiting for the reconciliation, kapp gives confidence to the end user that all the changes have been applied successfully and the resources are in working state.

## 3. List all the resources(across namespaces) owned by an app

While deploying kapp, we had provided <appName>. With the help of this <appName>, kapp will show all the resources which were applied via this app. In this way, you can get a quick overview of all the resources spread across various namespaces belonging to that app.

Let's see this with the help of an example.

1. In this example, our application consist of two parts: redis db and application itself. Redis deployment and its corresponding service exist in `database` namespace while application and its service exist in `application` namespace. Let's deploy this config file.

    `kapp deploy -a simple-app-with-db -f ./examples/simple-app-example-with-db/config.yml`


    ![](https://i.imgur.com/wwySn95.jpg)

2. List all the kapp deployed applications.
    
    `kapp ls`
    
    ![](https://i.imgur.com/X809oqV.png)

3. List all the resources owned by the application `simple-app-with-db`. It will show all the resources across all the namespaces which were deployed with help of this application.

    `kapp inspect -a simple-app-with-db`
    
    ![](https://i.imgur.com/UinvkVi.png)

    As we can see above, `kapp inspect` helps in getting a quick overview of all the resources present in both application as well as database namespace.

    

Kapp has other builtin functionalities e.g. Resource Version Management(to trigger Deployment rollout when ConfigMap changes), Records application deployment history etc. For detailed featues provided by kapp, please visit [here](https://carvel.dev/kapp/docs/latest/).

## References:

[Kapp Documentation](https://carvel.dev/kapp/docs/latest/)

[Carvel Tool Chain](https://carvel.dev/)

[Helm with Kapp](https://sridhar-vennela.medium.com/installing-helm-charts-using-carvels-kapp-tool-2e9bfe0cd8a2)

