Home > OS >  Deploy separate k8s manifest files
Deploy separate k8s manifest files

Time:07-23

I have a Spring boot application and I deploy the application to Kubernetes using a single k8s.yml manifest file via Github actions. This k8s.yml manifest contains Secrets, Service, Ingress, Deployment configurations. I was able to deploy the application successfully as well. Now I plan to separate the Secrets, Service, Ingress, Deployment configurations into a separate file as secrets.yml, service.yml, ingress.yml and deployment.yml.

Previously I use the below command for deployment

kubectl: 1.5.4
command: |
    sed -e 's/$SEC/${{ secrets.SEC }}/g' -e 's/$APP/${{ env.APP_NAME }}/g' -e 's/$ES/${{ env.ES }}/g' deployment.yml | kubectl apply -f -

Now after the separation I use the below commands

kubectl: 1.5.4
command: |
  kubectl apply -f secrets.yml
  kubectl apply -f service.yml
  sed -e 's/$ES/${{ env.ES }}/g' ingress.yml | kubectl apply -f -
  sed -e 's/$SEC/${{ secrets.SEC }}/g' -e 's/$APP/${{ env.APP_NAME }}/g' deployment.yml | kubectl apply -f -

But some how the application is not deploying correctly, I would like to know if the command which I am using is correct or not

CodePudding user response:

You can consider perform the sed first, then apply all files kubectl apply -f . instead of going one by one. Append --recursive if you have files in sub folder to apply, too.

CodePudding user response:

Like the other answer says, you can ask kubectl to apply all files recursively in a directory.

Now the sed replaces are soon going to become overwhelming as the resources and configuration grow.

That is why kubctl comes with integrated kustomize support: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/

In short:

  1. Break up all kubernetes resources into smaller files/components, put them in a directory.
  2. Place a file called kustomization.yaml in same directory.
  3. In the kustomization.yaml configure which file you want to apply, in which order, and also do some on-the-fly edits.

And apply with -k flag:

kubectl apply -k <kustomization_directory>
  • Related