how to ignore random kubernetes pod name in deployment file

4/15/2020

Below is my kubernetes deployment file -

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: boxfusenew
  labels:
    app: boxfusenew
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: boxfusenew
    spec:
      containers:
      - image: sk1997/boxfuse:latest
        name: boxfusenew
        ports:
        - containerPort: 8080

In this deployment file under container tag boxfusenew pod name is specified. So I want the pod generated by deployment file should have the boxfusenew name but the deployment is attaching some random value to it as- boxfusenew-5f6f67fc5-kmb7z.

Is it possible to ignore random values in pod name through deployment file??

-- Sujata Kale
kubernetes

2 Answers

4/15/2020

Not really, unless you create the Pod itself and not a deployment.

According to Kubernetes documentation:

Each object in your cluster has a Name that is unique for that type of resource. Every Kubernetes object also has a UID that is unique across your whole cluster.

For example, you can only have one Pod named myapp-1234 within the same namespace, but you can have one Pod and one Deployment that are each named myapp-1234.

For non-unique user-provided attributes, Kubernetes provides labels and annotations.

If you create a Pod with a specific unique label, you can use this label to query the Pod, so no need of having the exact name.

You can use a jsonpath to query the values that you want from your Pod under that specific deployment. I've created an example that may give you an idea:

kubectl get pods -o=jsonpath='{.items[?(@.metadata.labels.app=="boxfusenew")].metadata.name}'

This would return the name of the Pod which contains the label app=boxfusenew. You can take a look into some other examples of jsonpath here and here.

-- Juliano Costa
Source: StackOverflow

4/15/2020

First what kind of use case that you want to achieve? If you want to simply get available pods belongs to certain deployment you can use label and selector. For example:

kubectl -n <namespace> get po -l <key>=<value>
-- irvifa
Source: StackOverflow