k8s create ephemeral copies of a pod

74 views Asked by At

I'd like to create a copy of a k8s pod on the fly, and patch it with some custom configurations.

Unfortunately, I don't really know where to start from...

  my-service
    - kustomization.yaml
    - deployment.yaml

And then

kubectl apply -k ./path/to/my-service --override `{ "image": "foo-1", "name": "foo-1" }`

the override I am talking about should supply dynamic informations to the deployment, such as info I only have at build time, etc.


A.C

  • [ ] The original my-service pod should not be changed, the on-the-fly-deployment should create a new, ephemeral, pod.
  • [ ] The new ephemeral pod should have all the informations from the original
1

There are 1 answers

0
ITChap On

You could use a simple base and overlay:

my-service/
  base/
    kustomization.yml
    deployment.yml
  overlays/
    ephemeral/
      kustomization.yml

my-service/base/kustomization.yml:

resources:
  - deployment.yml

If you don't need a specific name for the ephemeral deployment:

my-service/overlays/ephemeral/kustomization.yml:

resources:
  - ../../base

nameSuffix: '-ephemeral'

images:
  - name: myImage
    newName: foo-1

replicas:
  - name: my-deployment
    count: 1

If you need a specific name you will have to patch the name in my-service/overlays/ephemeral/kustomization.yml. You can then run:

kubectl apply -k my-service/base
kubectl apply -k my-service/overlays/ephemeral

To be clear, this will create two deployments: the original and one deployment of a single pod. Not one deployment and one lone pod.