geerlingguy / ansible-for-kubernetes

Ansible and Kubernetes examples from Ansible for Kubernetes Book
https://www.ansibleforkubernetes.com
MIT License
691 stars 314 forks source link

Using 'docker_* tasks' conflicts with minikube environment from chapter 2. #92

Open gimballock opened 3 years ago

gimballock commented 3 years ago

https://github.com/geerlingguy/ansible-for-kubernetes/blob/555e16d04326ce54d998f7ec78e753799074f47e/ansible-containers/main.yml#L11

If using the same shell env from chapter 2 where we ran:

$ minikube docker-env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://127.0.0.1:55002" export DOCKER_CERT_PATH="/Users/eprice/.minikube/certs" export MINIKUBE_ACTIVE_DOCKERD="minikube"

To point your shell to minikube's docker-daemon, run:

eval $(minikube -p minikube docker-env)

$ eval $(minikube docker-env)

Then I get errors with 'docker_image' and 'docker_container' like this:

TASK [Ensure Docker registry image is present.] ***** fatal: [127.0.0.1]: FAILED! => {"changed": false, "msg": "Error connecting: Error while fetching server API version: HTTPSConnectionPool(host='127.0.0.1', port=55002): Max retries exceeded with url: /version (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10bf36970>: Failed to establish a new connection: [Errno 61] Connection refused'))"}

To get around this I have to either use a new shell or run the following:

$ minikube docker-env -u unset DOCKER_TLS_VERIFY; unset DOCKER_HOST; unset DOCKER_CERT_PATH; unset MINIKUBE_ACTIVE_DOCKERD; $ eval $(minikube docker-env -u)

typ-ex commented 3 years ago

Here's what I've found

https://github.com/geerlingguy/ansible-for-kubernetes/issues/88

gimballock commented 3 years ago

After downgrading kubernetes and openshift python packages and restarting minikube I still see the same issue.

$ pip3 list
Package             Version
------------------- ---------
-ubernetes          11.0.0
...
docker-py           1.10.6
docker-pycreds      0.4.0
...
kubernetes          11.0.0
...
openshift           0.11.2
...

$ minikube stop
$ minikube start
😄  minikube v1.17.1 on Darwin 11.2.1
✨  Using the docker driver based on existing profile
👍  Starting control plane node minikube in cluster minikube
🔄  Restarting existing docker container for "minikube" ...
🐳  Preparing Kubernetes v1.20.2 on Docker 20.10.2 ...
🔎  Verifying Kubernetes components...
🌟  Enabled addons: storage-provisioner, default-storageclass

❗  /usr/local/bin/kubectl is version 1.18.6, which may have incompatibilites with Kubernetes 1.20.2.
    ▪ Want kubectl v1.20.2? Try 'minikube kubectl -- get pods -A'
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

$ ansible-playbook -i inventory main.yml
...
TASK [Create and start the build container.]
...
"msg": "Error connecting: Error while fetching server API version: HTTPSConnectionPool(host='127.0.0.1', port=55002): Max retries exceeded with url: /version (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:1123)')))"
typ-ex commented 3 years ago

Sorry, I should have read the error more. What version of python are you using?

gimballock commented 3 years ago

Sorry for the delay, Python 3.9.2

typ-ex commented 3 years ago

I think what's happening is that you have the incorrect python compatibility with docker, or at least that is a part of it

Given this ticket, which I'm surprised you didn't get this error

https://github.com/ansible/ansible/issues/60748

Uninstall docker-py, and run pip3 install docker