Skip to content

Instantly share code, notes, and snippets.

@nelsonyaccuzzi
Last active November 18, 2022 22:43
Show Gist options
  • Save nelsonyaccuzzi/18555ec62c5271defdac59d8dbc2d6da to your computer and use it in GitHub Desktop.
Save nelsonyaccuzzi/18555ec62c5271defdac59d8dbc2d6da to your computer and use it in GitHub Desktop.
---
- name: Install Kubernetes
hosts: localhost
become: yes
vars:
k8s_version: 1.25
os: "xUbuntu_22.04"
tasks:
- name: Update all packages to their latest version
apt:
name: "*"
state: latest
update_cache: yes
- name: Download gpg keys
get_url:
url: "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/{{ os }}/Release.key"
dest: /etc/apt/trusted.gpg.d/libcontainers-archive-keyring.asc
mode: '0644'
force: true
- name: Download gpg key
get_url:
url: "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/{{ k8s_version }}/{{ os }}/Release.key"
dest: /etc/apt/trusted.gpg.d/libcontainers-crio-archive-keyring.asc
mode: '0644'
force: true
- name: Add CRI-O Repository
apt_repository:
repo: "deb [signed-by=/etc/apt/trusted.gpg.d/libcontainers-archive-keyring.asc] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/{{ os }}/ /"
state: present
filename: devel:kubic:libcontainers:stable.list
- name: Add CRI-O Repository
apt_repository:
repo: "deb [signed-by=/etc/apt/trusted.gpg.d/libcontainers-crio-archive-keyring.asc] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/{{ k8s_version }}/{{ os }}/ /"
state: present
filename: "devel:kubic:libcontainers:stable:cri-o:{{ k8s_version }}.list"
- name: Install CRI-O
apt:
name:
- cri-o
- cri-o-runc
state: present
- name: Load Kernel modules
modprobe:
name: overlay
state: present
- name: Load Kernel modules
modprobe:
name: br_netfilter
state: present
- name: Create Kernel module load config file
copy:
dest: /etc/modules-load.d/k8s.conf
content: |
overlay
br_netfilter
- name: Set sysconfig
ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: '1'
sysctl_set: yes
- name: Set sysconfig
ansible.posix.sysctl:
name: net.bridge.bridge-nf-call-iptables
value: '1'
sysctl_set: yes
- name: Set sysconfig
ansible.posix.sysctl:
name: net.bridge.bridge-nf-call-ip6tables
value: '1'
sysctl_set: yes
- name: Install CRI-O
apt:
name:
- apt-transport-https
- ca-certificates
- curl
state: present
- name: Download gpg key
get_url:
url: "https://packages.cloud.google.com/apt/doc/apt-key.gpg"
dest: /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg
mode: '0644'
force: true
- name: Add K8S Repository
apt_repository:
repo: "deb [signed-by=/etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main"
state: present
filename: kubernetes.list
- name: Install K8s packages
apt:
name:
- "kubectl"
- "kubeadm"
- "kubelet"
state: present
- name: Make sure a service unit is running
systemd:
state: started
name: crio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment