goal and the issue
To have a container/Pod deployment that can be continously running. The command the container should execute is: /usr/local/bin/python3
and the args to the command are: "-c $'import time\\nwhile (True):\\n print(\".\");time.sleep(5);'"
. However, when I execute kubectl apply -f "PATH_TO_THE_KUBERNETES_YAML_FILE"
the deployment errs with this Python exception: IndentationError: unexpected indent
.
The Pod deployment is used as the medium for calling Python code that interacts with the Certbot client as part of tasks when using LetsEncrypt certificates.
See the project here
So it should be possible to deploy the Pod >> do a kubectl exec ...
into the container running as part of the Kubernetes deployment.
tried:
Various ways of defining the Kubernetes command args line.
- Via the exec Python option. E.g.:
python3 -c exec(\"import time\nwhile True: print(\".\");time.sleep(5);\")
- Enclosing the code to execute with different combinations of ` and ".
$'textwrap.dedent("""import time while True: print(".") time.sleep(5)""")'
...tried using:
args: - "-c $'import time\\nwhile (True):\\n print(\".\");time.sleep(5);'"
as an alternative to
args: ["-c $'import time\\nwhile (True):\\n print(\".\");time.sleep(5);'"]
confirmed that the Python code itself works.
- both by using
Python3 -c "..."
directly and by calling it via adocker run
command to a container from this Dockerfile - I have done the usual Googling, Stack* search and so forth. I've also been on the official Kubernetes GitHub repo page and search through the issues there. Closed as well as open. And I have not seen any issue matching this one.
- Kubectl does not complain when doing
...apply -f YAML_FILE
, in regards to the format of the YAML file and to the adherence of the Pod deployment specification. - Tried with some bash code instead:
["/bin/bash", "-ecx", "while :; do printf '.'; sleep 5 ; done"]
<-- that works.
further info
- Python is v3.7.2
- Kubernetes is v1.12.5-gke.10
It seems to be the combination of specifying the Python code in a Kubernetes Pod deployment YAML file ... that doesn't go well with Pythons requirement of significant whitespace and indentation. As you can read in the #tried section, it works when calling Python directly or via a Docker run/exec command.
How can I troubleshoot this?