Kubernetes can be installed and configured many ways and Dcoker DEsktop will give you one version. Although Docker Desktop will never give you the same experience as a multi-node Kubernetes cluster configured according to your preference, the init containers guide should have worked. I tried it now on macOS.
I ams till using Docker Desktop v4.16.2, which could be a difference if you are using another version, but the error message indicates
How did you create the pod and where did you get the error message?
The “unexpected args” error message indicates that you have not followed the documentation properly and you tried to do something like this:
cat <<EOF | kubectl apply -
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app.kubernetes.io/name: MyApp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]
EOF
If you choose that way, you need to make sure that the cat command in the subshell is not interpeted by your host shell and also that you use the kubectl command properly and pass “-” to the flag "-f
. Like this
cat <<'EOF' | kubectl apply -f -
Note the apostrophe around EOF (or whatever you use as a separator). So the full command would be
cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app.kubernetes.io/name: MyApp
spec:
containers:
- name: myapp-container
image: busybox:1.28
command: ['sh', '-c', 'echo The app is running! && sleep 3600']
initContainers:
- name: init-myservice
image: busybox:1.28
command: ['sh', '-c', "until nslookup myservice.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for myservice; sleep 2; done"]
- name: init-mydb
image: busybox:1.28
command: ['sh', '-c', "until nslookup mydb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done"]
EOF
So it looks like it had nothing to do with Docker Desktop.