<p>Looking any kubernetes command which can help me to delete all the related resources of the deployment excluding specific one.</p>

<p><strong>Example:-</strong></p>

<p>Below is my two deployment echo1 &amp; echo2 now I want to delete all the related resources which belongs to echo1 will be delete and echo2 will remain as it is. </p>

<pre><code>NAME                         READY   STATUS    RESTARTS   AGE
pod/echo1-559ffc8757-th      1/1     Running   0          22s
pod/echo2-5c6c8ff4b-x56      1/1     Running   0          15s

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/echo1   ClusterIP   10.10.x.x       &lt;none&gt;        80/TCP    39m
service/echo2   ClusterIP   10.10.x.x       &lt;none&gt;        80/TCP    38m

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/echo1   1/1     1            1           22s
deployment.apps/echo2   1/1     1            1           15s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/echo1-559ffc8      1         1         1       22s
replicaset.apps/echo2-5c6c8ff      1         1         1       15s
</code></pre>

<p>my deployement file :-</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: echo1
spec:
  ports:
  - port: 80
    targetPort: 5678
  selector:
    app: echo1
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: echo1
spec:
  selector:
    matchLabels:
      app: echo1
  replicas: 1
  template:
    metadata:
      labels:
        app: echo1
    spec:
      containers:
      - name: echo1
        image: hashicorp/http-echo
        args:
        - "-text=echo1"
        ports:
        - containerPort: 5678
~                             ```
</code></pre>

me25
<p>You can set a common label to connected resources and then delete by --selector</p>

<pre><code>$ kubectl delete all --selector=&lt;key&gt;=&lt;value&gt; -n &lt;namespace&gt;
or 
$ kubectl delete all -l &lt;key&gt;=&lt;value&gt; -n &lt;namespace&gt;

</code></pre>

<p>In your file modify like following and apply above command</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: echo1
  labels:
    app: echo1
spec:
  ports:
  - port: 80
    targetPort: 5678
  selector:
    app: echo1
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: echo1
  labels:
    app: echo1
spec:
  selector:
    matchLabels:
      app: echo1
  replicas: 1
  template:
    metadata:
      labels:
        app: echo1
    spec:
      containers:
      - name: echo1
        image: hashicorp/http-echo
        args:
        - "-text=echo1"
        ports:
        - containerPort: 5678

</code></pre>

<p>Click <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/#deleting-resources" rel="nofollow noreferrer">here</a> to see more examples</p>
