skaffold
skaffold copied to clipboard
sync does not sync files to initContainers in Deployment
Expected behavior
When I change a file, and restart deployment, the file change will appear in the init containers that use the same image.
Actual behavior
The init container have stale source code.
Information
- Skaffold version: v2.6.2
- Operating system: NixOS
- Installed via: nix
- Contents of skaffold.yaml:
apiVersion: skaffold/v4beta5
kind: Config
metadata:
name: my-project
build:
artifacts:
- image: my-image
context: .
docker:
dockerfile: backend/Dockerfile
sync:
infer:
- backend/**/*.py
- backend/src/web/templates/*.j2.html
Steps to reproduce the behavior
Create a deployment where my-image
is used in both a container and and init-container. Change file and see that it is only updated in the container, not the init-container.
Hey @carlbordum, thanks for opening this issue. 🤔 could you please provide more details about your use case? What do you exactly mean by "and restart deployment"? Is that restart triggered by Skaffold on a manifest change? or by your code/you? What's the configuration of your Pod?
From my understanding, and taking a look to K8s docs my understanding about init containers is:
- Will always run until completition
- When all of the init containers have run to completion, kubelet initializes the application containers for the Pod and runs them as usual
With that said, Skaffold triggers the sync against only the application containers, due to the init containers, at the moment the application is running, will be already terminated, and running a kubectl command to copy files to them won't work (the init containers are not active/live).
Perhaps, are you trying the new API for sidecar containers?
Thanks! 😄
Thank you for the response. I think I was just scaling the deployment to 0 manually, then back and expecting the new init containers to have synced files.
AFAIK skaffold sync runs kubectl cp
kind of operation under the hood which merely copies files into the running container. When ever the container is restarted these files are lost. The init container only runs when a Pod is starting up, and at that point the image will be pristine without any extra files copied by Skaffold. Right?