Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear documentation about sidecar containers #42762

Closed
parimaljanagithub opened this issue Aug 28, 2023 · 18 comments · Fixed by #43346
Closed

Unclear documentation about sidecar containers #42762

parimaljanagithub opened this issue Aug 28, 2023 · 18 comments · Fixed by #43346
Assignees
Labels
language/en Issues or PRs related to English language needs-kind Indicates a PR lacks a `kind/foo` label and requires one. sig/docs Categorizes an issue or PR as relevant to SIG Docs. sig/node Categorizes an issue or PR as relevant to SIG Node. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@parimaljanagithub
Copy link

restartPolicy under initContainers is not allowing to create Jobs specified into the below documents

Error Message:
Job in version "v1" cannot be handled as a Job: strict decoding error: unknown field "spec.template.spec.initContainers[0].restartPolicy"

Document Link:
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#pod-restart-reasons

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Aug 28, 2023
@thisisharrsh
Copy link
Contributor

Hi @parimaljanagithub, I believe the error message you are getting is because you might have used restartpolicy feild under the initcontainers section. But it is not allowed under the initcontainers.

/language en

@k8s-ci-robot k8s-ci-robot added the language/en Issues or PRs related to English language label Aug 28, 2023
@thisisharrsh
Copy link
Contributor

Page related to the issue: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#pod-restart-reasons
/sig docs
/sig node

@k8s-ci-robot k8s-ci-robot added sig/docs Categorizes an issue or PR as relevant to SIG Docs. sig/node Categorizes an issue or PR as relevant to SIG Node. labels Aug 28, 2023
@parimaljanagithub
Copy link
Author

parimaljanagithub commented Aug 28, 2023

Hi @thisisharrsh ,
Below is the Job configuration:

kind: Job
metadata:
  name: myjob
spec:
  template:
    spec:
      containers:
        - name: myjob
          image: alpine:latest
          command: ['sh', '-c', 'echo "logging" > /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt
      initContainers:
        - name: logshipper
          image: alpine:latest
          restartPolicy: Always
          command: ['sh', '-c', 'tail -F /opt/logs.txt']
          volumeMounts:
            - name: data
              mountPath: /opt
      restartPolicy: Never
      volumes:
        - name: data
          emptyDir: {}```

@thisisharrsh
Copy link
Contributor

Could you please provide the code block with proper indentation?

@parimaljanagithub
Copy link
Author

updated above section

@tamilselvan1102
Copy link

The indentation should be corrected as below

initContainers:
      - name: logshipper
        image: alpine:latest
        restartPolicy: Always
        command: ['sh', '-c', 'tail -F /opt/logs.txt']
        volumeMounts:
          - name: data
            mountPath: /opt
        restartPolicy: Never

@tamilselvan1102
Copy link

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 29, 2023
@sftim
Copy link
Contributor

sftim commented Aug 30, 2023

https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#api-for-sidecar-containers mentions a feature gate, but doesn't make it explicitly clear that you need to enable it. The feature gate is named SidecarContainers.

The fix I recommend:

/remove-kind bug

I don't think there is anything actually incorrect.
/triage accepted
/retitle Unclear documentation about sidecar containers

@k8s-ci-robot k8s-ci-robot changed the title Issue with k8s.io/docs/concepts/workloads/pods/init-containers/ Unclear documentation about sidecar containers Aug 30, 2023
@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. kind/bug Categorizes issue or PR as related to a bug. labels Aug 30, 2023
@T-Lakshmi
Copy link
Contributor

Is anybody working to fix this issue? If no, i can take it.

@tamilselvan1102
Copy link

/assign @T-Lakshmi

@justankiit
Copy link

Feel free to involve me, if you need any help.

@T-Lakshmi
Copy link
Contributor

@kumarankit999 Sure, Thank you.

@T-Lakshmi
Copy link
Contributor

PR raised to fix the issue #43346.

@sftim
Copy link
Contributor

sftim commented Oct 20, 2023

Also see #43610

@sftim
Copy link
Contributor

sftim commented Nov 8, 2023

To learn more, you can read (but not plagiarize) https://loft.sh/blog/kubernetes-init-containers/

@Sivakajan-tech
Copy link

Hi, I also having this problem I tried to add restartPolicy as Always to under containers and init containers, but I get the same error.

Error from server (BadRequest): error when creating "MakeChunks/hello.yaml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.template.spec.containers[0].restartPolicy", unknown field "spec.template.spec.initContainers[0].restartPolicy"
apiVersion: apps/v1
kind: Deployment
metadata:
  name: bash
spec:
  selector:
    matchLabels:
      app: bash
  template:
    metadata:
      labels:
        app: bash
    spec:
      restartPolicy: Always  #1
      containers: # List of containers, not another list within spec
        - name: bash
          image: ubuntu:latest
          resources:
            limits:
              cpu: "700m"
              memory: "200Mi"
            requests:
              cpu: "700m"
              memory: "200Mi"
          resizePolicy:
            - resourceName: "cpu"
              restartPolicy: "NotRequired"
            - resourceName: "memory"
              restartPolicy: "RestartContainer"
          command: ["tail", "-f", "/dev/null"]
          restartPolicy: Always  #2
      initContainers: # Optional init containers, not nested in another list
        - name: init-1
          image: ubuntu:latest
          command:
            - sh
            - "-c"
            - "sleep 1s \n"
          restartPolicy: Always  #3

I do not got any errors for the # 1 restartPolicy, but #2 and #3 are gave the error mentioned at the top.

Im using Minikube, and my

 % kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.3", GitCommit:"25b4e43193bcda6c7328a6d147b1fb73a33f1598", GitTreeState:"clean", BuildDate:"2023-06-14T09:47:38Z", GoVersion:"go1.20.5", Compiler:"gc", Platform:"darwin/arm64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27+", GitVersion:"v1.27.0-rc.0", GitCommit:"cf60ee25590ac79334f823b7f03cf33105a442c1", GitTreeState:"clean", BuildDate:"2023-03-23T18:59:06Z", GoVersion:"go1.20.2", Compiler:"gc", Platform:"linux/arm64"}

CC: @tamilselvan1102 @thisisharrsh @T-Lakshmi Your suggestions highly appriciatable

@stmcginnis
Copy link
Contributor

stmcginnis commented Mar 20, 2024 via email

@Sivakajan-tech
Copy link

Thanks @stmcginnis. I updated my k8s

 % kubectl version
Client Version: v1.29.3
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.0

Even though I can not use Never and OnFailure in both places. (#1 and #3 I put this marker in the above comment). It says,

The Deployment "bash" is invalid: spec.template.spec.restartPolicy: Unsupported value: "Never": supported values: "Always"
The Deployment "bash" is invalid: spec.template.spec.initContainers[0].restartPolicy: Unsupported value: "Never": supported values: "Always"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/en Issues or PRs related to English language needs-kind Indicates a PR lacks a `kind/foo` label and requires one. sig/docs Categorizes an issue or PR as relevant to SIG Docs. sig/node Categorizes an issue or PR as relevant to SIG Node. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants