How do I write an okteto-pipeline that restarts the pod after building?

When I re-deploy my application after changes have been made, it doesn’t override the existing service until a manual restart has been made or if it was manually destroyed before.

How can I write an okteto-pipeline.yml that restarts after building or destroys before building?

Could you share your current manifest? This is usually achieved using tools like helm or kustomize and using a different tag on each build. You can use the envvar OKTETO_GIT_COMMIT for this end, or use the build section of the okteto manifest v2:

I have used the manifest and pipeline from the Spring Microservices demonstration.

My manifest for the application (located in folder k8s) is:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user
  labels:
    app: user
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user
  template:
    metadata:
      labels:
        app: user
    spec:
      containers:
      - name: user
        image: okteto.dev/user-service:dev
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: user
  labels:
    app: user
    spring-boot: "true"
spec:
  type: ClusterIP
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: user

Then in my okteto-pipeline I have this:

deploy:
  - okteto build -t okteto.dev/user-service:dev -f user-service/Dockerfile user-service
  - kubectl apply -f k8s
devs:
  - user-service/okteto.yml

Yes, that’s always reusinng the same tag okteto.dev/user-service:dev.
If you don’t want to migrate to helm, you can update your pipeline with this:

deploy:
  - okteto build -t okteto.dev/user-service:dev -f user-service/Dockerfile user-service
  - kubectl apply -f k8s
  - kubectl rollout restart deployment/user
1 Like

Thank you so much, that worked perfectly!
I hadn’t thought about using kubectl for that.

I have an additional question…
At the moment I am using the deploy button in the Readme to deploy it as a whole, but I want to deploy it from a GitHub Action (preferably even able to deploy each service seperately). I have tried looking at examples but I am still new to this so it’s hard to understand.
Is there a way to deploy it like that from GitHub Actions?

Yes, we have our own GitHub Actions for this. There is a sample here:

1 Like

Thank you for the help, and thank you for the quick replies!