I’m having a k3s (single node) kubernetes cluster and try to make a deployment on it via ansible.
I know of cource that I use a k8s collection for k3s, but maybe it can be solved anyhow.
The relevant part of my playbook is:
---
- hosts: k3s_cluster
become: yes
tasks:
- name: Create a Deployment by reading the definition from a local file
kubernetes.core.k8s:
api_key: mytoken
state: present
src: deployment.yml
The deployment file is simple.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
If I do it directly via kubectl it works.
The config exists on the target host(and also on my local machine) in ~/.kube/config. Specifying that location doesn’t help.
2
Answers
Provide the
host
to access the API server. If not using a tls cert chain that can be validated by your system certificates you may also needvalidate_certs
set to false.Ansible+k3s on Raspberry Pi CM4 cluster
How to install k3s on Raspberry Pi CM4 cluster using Ansible
Requirements:
For Raspberry Pi / CM4
added to
For Ansible
Scripts and configuration files are available here:
Add k3s configuration into the environment if needed on master node after the deployment what usually is not needed.
Edit the file
Add the below entry:
Explanation:
source is a Bash shell built-in command that executes the content of the file passed as an argument in the current shell. It has a synonym in . (period).