book-of-kubernetes / examples

Examples for The Book of Kubernetes
MIT License
146 stars 71 forks source link

Ansible playbook failing at "Deploy Database Directly" (Chap 01 / non-standard Vagrant box) #32

Open jeff-tillinghast opened 10 months ago

jeff-tillinghast commented 10 months ago

Hi all-- Because I'm running on an M1 Mac, I'm trying to make a non-standard local Vagrant configuration work. I'm running Vagrant with Parallels using box bento/ubuntu-22.04-arm64 (the recommended box per Parallels). In the Vagrantfile, I've changed line 12 to point to the according box, and line 18 to change from :virtual_box to :parallels. The box builds, and the playbook initiates through 'TASK [todo : python prerequisites]', but then it loses the plot-- it skips the next three steps and finally hits failure loop with multiple failures in 'deploy database directly', all referencing 'Invalid kube-config file. No configuration found.':

Output TASK [todo : python prerequisites] ***** changed: [host01]

TASK [todo : manifests directory] ** skipping: [host01]

TASK [todo : stage manifests] ** skipping: [host01] => (item=database.yaml) skipping: [host01] => (item=application.yaml) skipping: [host01] => (item=service.yaml) skipping: [host01] => (item=scaler.yaml) skipping: [host01]

TASK [todo : deploy database using operator] *** skipping: [host01]

TASK [todo : deploy database directly] ***** FAILED - RETRYING: [host01]: deploy database directly (10 retries left). [...]

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions.CoreException: Could not create API client: Invalid kube-config file. No configuration found. failed: [host01] (item=pvc.yaml.j2) => {"ansible_loop_var": "item", "attempts": 10, "changed": false, "item": "pvc.yaml.j2", "msg": "Could not create API client: Invalid kube-config file. No configuration found."}

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions.CoreException: Could not create API client: Invalid kube-config file. No configuration found. failed: [host01] (item=database-secret.yaml.j2) => {"ansible_loop_var": "item", "attempts": 10, "changed": false, "item": "database-secret.yaml.j2", "msg": "Could not create API client: Invalid kube-config file. No configuration found."}

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions.CoreException: Could not create API client: Invalid kube-config file. No configuration found. failed: [host01] (item=database-deploy.yaml.j2) => {"ansible_loop_var": "item", "attempts": 10, "changed": false, "item": "database-deploy.yaml.j2", "msg": "Could not create API client: Invalid kube-config file. No configuration found."}

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.kubernetes.core.plugins.module_utils.k8s.exceptions.CoreException: Could not create API client: Invalid kube-config file. No configuration found. failed: [host01] (item=database-service.yaml.j2) => {"ansible_loop_var": "item", "attempts": 10, "changed": false, "item": "database-service.yaml.j2", "msg": "Could not create API client: Invalid kube-config file. No configuration found."}

PLAY RECAP ***** host01 : ok=11 changed=10 unreachable=0 failed=1 skipped=3 rescued=0 ignored=0

Ansible failed to complete successfully. Any error output should be visible above. Please fix these errors and try again.

/Output

The only other modification I made to the Vagrant was adding 'ansible.compatibility_mode = "2.0" to both of the 'config.vm.provision' blocks in response to output during my first test run. But adding/removing that condition doesn't affect the results or the output above.

Thanks for any help!

jeff-tillinghast commented 10 months ago

Adding: I was able to use the image to continue through Chapter 1 until I got to the sample application. As a result of the failures above, K3S did not install properly. I manually installed K3S using the script at http://get.k3s.io, and it runs satisfactorily. But obviously the sample application did not install and start, so there are no pods running with the application or database.

disposedtrolley commented 1 month ago

@jeff-tillinghast I think it'll be a challenge to get this working, if it's at all possible.

The following change will allow k3s to install successfully and vagrant up to run without erroring:

diff --git a/setup/roles/k3s/defaults/main.yaml b/setup/roles/k3s/defaults/main.yaml
index 73fc135..5248305 100644
--- a/setup/roles/k3s/defaults/main.yaml
+++ b/setup/roles/k3s/defaults/main.yaml
@@ -1,3 +1,3 @@
 ---
-k3s_version: "v1.23.4+k3s1"
-k3s_url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s
\ No newline at end of file
+k3s_version: "v1.30.1+k3s1"
+k3s_url: https://github.com/k3s-io/k3s/releases/download/{{ k3s_version }}/k3s-arm64
\ No newline at end of file

The next issue occurs within the VM when K8s attempts to start the todo app:

vagrant@host01:~$ sudo k3s kubectl get pods
NAME                       READY   STATUS             RESTARTS      AGE
todo-db-66d6d87b67-psf98   1/1     Running            0             3m10s
todo-7c94fcc877-6zh69      0/1     CrashLoopBackOff   4 (88s ago)   3m9s
todo-7c94fcc877-5w5gd      0/1     CrashLoopBackOff   4 (80s ago)   3m9s
todo-7c94fcc877-xh7ph      0/1     CrashLoopBackOff   4 (73s ago)   3m9s

Examining the logs:

vagrant@host01:~$ sudo k3s kubectl logs todo-7c94fcc877-6zh69
exec /usr/local/bin/docker-entrypoint.sh: exec format error

which is due to the todo app's container image (referenced in setup/roles/todo/templates/application.yaml.j2) being built for amd64 only: https://hub.docker.com/r/bookofkubernetes/todo