Last active
August 27, 2018 03:47
-
-
Save gjcarneiro/b0087cd1c0b56b5fcc65f37b473a7482 to your computer and use it in GitHub Desktop.
ansible playbook to install kubernetes for devbox on ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This playbook installs kubernetes on the local host for development purposes | |
# only. This assumes there is a local docker daemon running, and that docker | |
# doesn't use the latest "overlay2" filesystem driver (which kubernetes doesn't | |
# support). | |
# | |
# Should work on Ubuntu 16.04, in theory, and was tested on 17.04. | |
# | |
- hosts: all | |
connection: local | |
tasks: | |
- name: check if kubernetes is installed | |
stat: path=/etc/kubernetes/admin.conf | |
register: admin_conf | |
- apt_key: | |
url: "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | |
state: present | |
become: yes | |
when: not admin_conf.stat.exists | |
- apt_repository: | |
repo: deb http://apt.kubernetes.io/ kubernetes-xenial main | |
state: present | |
become: yes | |
when: not admin_conf.stat.exists | |
- apt: | |
name: "{{item}}" | |
become: yes | |
with_items: | |
- kubelet | |
- kubeadm | |
- kubectl | |
- kubernetes-cni | |
when: not admin_conf.stat.exists | |
- lineinfile: | |
dest: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf | |
state: absent | |
regexp: '^Environment="KUBELET_NETWORK_ARGS' | |
become: yes | |
when: not admin_conf.stat.exists | |
- command: kubeadm init | |
become: yes | |
when: not admin_conf.stat.exists | |
- file: | |
path: "/{{ansible_env.HOME}}/.kube" | |
state: directory | |
mode: 0700 | |
- command: cp {{ansible_env.HOME}}/.kube/config {{ansible_env.HOME}}/.kube/config.backup | |
ignore_errors: yes | |
- command: cp /etc/kubernetes/admin.conf {{ansible_env.HOME}}/.kube/config | |
become: yes | |
- file: path="{{ansible_env.HOME}}/.kube/config" owner="{{ansible_env.USER}}" | |
become: yes | |
- command: kubectl taint nodes --all node-role.kubernetes.io/master- | |
ignore_errors: yes | |
# https://github.com/kubernetes/kubernetes/issues/45828 | |
- command: kubectl -n kube-system create configmap kube-dns --from-literal=upstreamNameservers='["dns server ip here"]' | |
ignore_errors: yes | |
- command: kubectl -n kube-system edit configmap kube-dns | |
- command: kubectl -n kube-system delete pod -l k8s-app=kube-dns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ansible-playbook kubeadm-devbox.yaml -v
Using /etc/ansible/ansible.cfg as config file
PLAY [all] ***************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [localhost]
TASK [check if kubernetes is installed] **********************************************************************************************************************
ok: [localhost] => {"changed": false, "stat": {"exists": false}}
TASK [apt_key] ***********************************************************************************************************************************************
ok: [localhost] => {"changed": false}
TASK [apt_repository] ****************************************************************************************************************************************
ok: [localhost] => {"changed": false, "repo": "deb http://apt.kubernetes.io/ kubernetes-xenial main", "state": "present"}
TASK [apt] ***************************************************************************************************************************************************
changed: [localhost] => (item=[u'kubelet', u'kubeadm', u'kubectl', u'kubernetes-cni']) => {"cache_update_time": 1535341440, "cache_updated": false, "changed": true, "item": ["kubelet", "kubeadm", "kubectl", "kubernetes-cni"], "stderr": "", "stderr_lines": [], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nThe following extra packages will be installed:\n cri-tools ebtables socat\nThe following NEW packages will be installed:\n cri-tools ebtables kubeadm kubectl kubelet kubernetes-cni socat\n0 upgraded, 7 newly installed, 0 to remove and 7 not upgraded.\nNeed to get 53.7 MB of archives.\nAfter this operation, 351 MB of additional disk space will be used.\nGet:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ trusty-updates/main ebtables amd64 2.0.10.4-3ubuntu1.14.04.2 [77.2 kB]\nGet:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ trusty/universe socat amd64 1.7.2.3-1 [302 kB]\nGet:3 http://apt.kubernetes.io/ kubernetes-xenial/main cri-tools amd64 1.11.0-00 [5309 kB]\nGet:4 http://apt.kubernetes.io/ kubernetes-xenial/main kubernetes-cni amd64 0.6.0-00 [5910 kB]\nGet:5 http://apt.kubernetes.io/ kubernetes-xenial/main kubelet amd64 1.11.2-00 [23.2 MB]\nGet:6 http://apt.kubernetes.io/ kubernetes-xenial/main kubectl amd64 1.11.2-00 [9394 kB]\nGet:7 http://apt.kubernetes.io/ kubernetes-xenial/main kubeadm amd64 1.11.2-00 [9420 kB]\nFetched 53.7 MB in 3s (13.7 MB/s)\nSelecting previously unselected package cri-tools.\n(Reading database ... 147853 files and directories currently installed.)\nPreparing to unpack .../cri-tools_1.11.0-00_amd64.deb ...\nUnpacking cri-tools (1.11.0-00) ...\nSelecting previously unselected package ebtables.\nPreparing to unpack .../ebtables_2.0.10.4-3ubuntu1.14.04.2_amd64.deb ...\nUnpacking ebtables (2.0.10.4-3ubuntu1.14.04.2) ...\nSelecting previously unselected package kubernetes-cni.\nPreparing to unpack .../kubernetes-cni_0.6.0-00_amd64.deb ...\nUnpacking kubernetes-cni (0.6.0-00) ...\nSelecting previously unselected package socat.\nPreparing to unpack .../socat_1.7.2.3-1_amd64.deb ...\nUnpacking socat (1.7.2.3-1) ...\nSelecting previously unselected package kubelet.\nPreparing to unpack .../kubelet_1.11.2-00_amd64.deb ...\nUnpacking kubelet (1.11.2-00) ...\nSelecting previously unselected package kubectl.\nPreparing to unpack .../kubectl_1.11.2-00_amd64.deb ...\nUnpacking kubectl (1.11.2-00) ...\nSelecting previously unselected package kubeadm.\nPreparing to unpack .../kubeadm_1.11.2-00_amd64.deb ...\nUnpacking kubeadm (1.11.2-00) ...\nProcessing triggers for man-db (2.6.7.1-1ubuntu1) ...\nProcessing triggers for ureadahead (0.100.0-16) ...\nSetting up cri-tools (1.11.0-00) ...\nSetting up ebtables (2.0.10.4-3ubuntu1.14.04.2) ...\nSetting up kubernetes-cni (0.6.0-00) ...\nSetting up socat (1.7.2.3-1) ...\nSetting up kubectl (1.11.2-00) ...\nProcessing triggers for ureadahead (0.100.0-16) ...\nSetting up kubelet (1.11.2-00) ...\nSetting up kubeadm (1.11.2-00) ...\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "The following extra packages will be installed:", " cri-tools ebtables socat", "The following NEW packages will be installed:", " cri-tools ebtables kubeadm kubectl kubelet kubernetes-cni socat", "0 upgraded, 7 newly installed, 0 to remove and 7 not upgraded.", "Need to get 53.7 MB of archives.", "After this operation, 351 MB of additional disk space will be used.", "Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ trusty-updates/main ebtables amd64 2.0.10.4-3ubuntu1.14.04.2 [77.2 kB]", "Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ trusty/universe socat amd64 1.7.2.3-1 [302 kB]", "Get:3 http://apt.kubernetes.io/ kubernetes-xenial/main cri-tools amd64 1.11.0-00 [5309 kB]", "Get:4 http://apt.kubernetes.io/ kubernetes-xenial/main kubernetes-cni amd64 0.6.0-00 [5910 kB]", "Get:5 http://apt.kubernetes.io/ kubernetes-xenial/main kubelet amd64 1.11.2-00 [23.2 MB]", "Get:6 http://apt.kubernetes.io/ kubernetes-xenial/main kubectl amd64 1.11.2-00 [9394 kB]", "Get:7 http://apt.kubernetes.io/ kubernetes-xenial/main kubeadm amd64 1.11.2-00 [9420 kB]", "Fetched 53.7 MB in 3s (13.7 MB/s)", "Selecting previously unselected package cri-tools.", "(Reading database ... 147853 files and directories currently installed.)", "Preparing to unpack .../cri-tools_1.11.0-00_amd64.deb ...", "Unpacking cri-tools (1.11.0-00) ...", "Selecting previously unselected package ebtables.", "Preparing to unpack .../ebtables_2.0.10.4-3ubuntu1.14.04.2_amd64.deb ...", "Unpacking ebtables (2.0.10.4-3ubuntu1.14.04.2) ...", "Selecting previously unselected package kubernetes-cni.", "Preparing to unpack .../kubernetes-cni_0.6.0-00_amd64.deb ...", "Unpacking kubernetes-cni (0.6.0-00) ...", "Selecting previously unselected package socat.", "Preparing to unpack .../socat_1.7.2.3-1_amd64.deb ...", "Unpacking socat (1.7.2.3-1) ...", "Selecting previously unselected package kubelet.", "Preparing to unpack .../kubelet_1.11.2-00_amd64.deb ...", "Unpacking kubelet (1.11.2-00) ...", "Selecting previously unselected package kubectl.", "Preparing to unpack .../kubectl_1.11.2-00_amd64.deb ...", "Unpacking kubectl (1.11.2-00) ...", "Selecting previously unselected package kubeadm.", "Preparing to unpack .../kubeadm_1.11.2-00_amd64.deb ...", "Unpacking kubeadm (1.11.2-00) ...", "Processing triggers for man-db (2.6.7.1-1ubuntu1) ...", "Processing triggers for ureadahead (0.100.0-16) ...", "Setting up cri-tools (1.11.0-00) ...", "Setting up ebtables (2.0.10.4-3ubuntu1.14.04.2) ...", "Setting up kubernetes-cni (0.6.0-00) ...", "Setting up socat (1.7.2.3-1) ...", "Setting up kubectl (1.11.2-00) ...", "Processing triggers for ureadahead (0.100.0-16) ...", "Setting up kubelet (1.11.2-00) ...", "Setting up kubeadm (1.11.2-00) ..."]}
TASK [lineinfile] ********************************************************************************************************************************************
ok: [localhost] => {"backup": "", "changed": false, "found": 0, "msg": ""}
TASK [command] ***********************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["kubeadm", "init"], "delta": "0:00:01.891547", "end": "2018-08-27 03:44:45.639426", "msg": "non-zero return code", "rc": 2, "start": "2018-08-27 03:44:43.747879", "stderr": "\t[WARNING Firewalld]: no supported init system detected, skipping checking for services\n\t[WARNING Service-Docker]: no supported init system detected, skipping checking for services\nI0827 03:44:44.136052 5467 kernel_validator.go:81] Validating kernel version\nI0827 03:44:44.136155 5467 kernel_validator.go:96] Validating kernel config\n\t[WARNING Service-Kubelet]: no supported init system detected, skipping checking for services\n[preflight] Some fatal errors occurred:\n\t[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist\n\t[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1\n\t[ERROR Swap]: running with swap on is not supported. Please disable swap\n\t[ERROR FileExisting-nsenter]: nsenter not found in system path\n\t[ERROR SystemVerification]: failed to get docker info: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?\n[preflight] If you know what you are doing, you can make a check non-fatal with
--ignore-preflight-errors=...
", "stderr_lines": ["\t[WARNING Firewalld]: no supported init system detected, skipping checking for services", "\t[WARNING Service-Docker]: no supported init system detected, skipping checking for services", "I0827 03:44:44.136052 5467 kernel_validator.go:81] Validating kernel version", "I0827 03:44:44.136155 5467 kernel_validator.go:96] Validating kernel config", "
t[WARNING Service-Kubelet]: no supported init system detected, skipping checking for services", "[preflight] Some fatal errors occurred:", "\t[ERROR FileConte
nt--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables does not exist", "\t[ERROR FileContent--proc-sys-net-ipv4-ip_fo
rward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1", "\t[ERROR Swap]: running with swap on is not supported. Please disable swap", "\t[ERROR File
Existing-nsenter]: nsenter not found in system path", "\t[ERROR SystemVerification]: failed to get docker info: Cannot connect to the Docker daemon at unix://
/var/run/docker.sock. Is the docker daemon running?", "[preflight] If you know what you are doing, you can make a check non-fatal with
--ignore-preflight-err ors=...
"], "stdout": "[init] using Kubernetes version: v1.11.2\n[preflight] running pre-flight checks\n[preflight] The system verification failed. Printing the output from the verification:\n\u001b[0;37mKERNEL_VERSION\u001b[0m: \u001b[0;32m3.13.0-156-generic\u001b[0m\n\u001b[0;37mCONFIG_NAMESPACES\u001b[0m: \u001b
[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_NET_NS\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_PID_NS\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u
001b[0;37mCONFIG_IPC_NS\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_UTS_NS\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_CGROUPS\u
001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_CGROUP_CPUACCT\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_CGROUP_DEVICE\u001b[0m: \u
001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_CGROUP_FREEZER\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_CGROUP_SCHED\u001b[0m: \u001b[0;32men
abled\u001b[0m\n\u001b[0;37mCONFIG_CPUSETS\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_MEMCG\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;3
7mCONFIG_INET\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_EXT4_FS\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_PROC_FS\u001b[0m:
\u001b[0;32menabled\u001b[0m\n\u001b[0;37mCONFIG_NETFILTER_XT_TARGET_REDIRECT\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m\n\u001b[0;37mCONFIG_NETFILTER
_XT_MATCH_COMMENT\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m\n\u001b[0;37mCONFIG_OVERLAYFS_FS\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m\n\u00
1b[0;37mCONFIG_AUFS_FS\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m\n\u001b[0;37mCONFIG_BLK_DEV_DM\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mO
S\u001b[0m: \u001b[0;32mLinux\u001b[0m\n\u001b[0;37mCGROUPS_CPU\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCGROUPS_CPUACCT\u001b[0m: \u001b[0;32menab
led\u001b[0m\n\u001b[0;37mCGROUPS_CPUSET\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCGROUPS_DEVICES\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;
37mCGROUPS_FREEZER\u001b[0m: \u001b[0;32menabled\u001b[0m\n\u001b[0;37mCGROUPS_MEMORY\u001b[0m: \u001b[0;32menabled\u001b[0m", "stdout_lines": ["[init] using
Kubernetes version: v1.11.2", "[preflight] running pre-flight checks", "[preflight] The system verification failed. Printing the output from the verification:
", "\u001b[0;37mKERNEL_VERSION\u001b[0m: \u001b[0;32m3.13.0-156-generic\u001b[0m", "\u001b[0;37mCONFIG_NAMESPACES\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u
001b[0;37mCONFIG_NET_NS\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_PID_NS\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_IPC_N
S\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_UTS_NS\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_CGROUPS\u001b[0m: \u001b[0;
32menabled\u001b[0m", "\u001b[0;37mCONFIG_CGROUP_CPUACCT\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_CGROUP_DEVICE\u001b[0m: \u001b[0;32menab
led\u001b[0m", "\u001b[0;37mCONFIG_CGROUP_FREEZER\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_CGROUP_SCHED\u001b[0m: \u001b[0;32menabled\u001
b[0m", "\u001b[0;37mCONFIG_CPUSETS\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_MEMCG\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCO
NFIG_INET\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_EXT4_FS\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_PROC_FS\u001b[0m:
\u001b[0;32menabled\u001b[0m", "\u001b[0;37mCONFIG_NETFILTER_XT_TARGET_REDIRECT\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m", "\u001b[0;37mCONFIG_NETFI
LTER_XT_MATCH_COMMENT\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m", "\u001b[0;37mCONFIG_OVERLAYFS_FS\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m
", "\u001b[0;37mCONFIG_AUFS_FS\u001b[0m: \u001b[0;32menabled (as module)\u001b[0m", "\u001b[0;37mCONFIG_BLK_DEV_DM\u001b[0m: \u001b[0;32menabled\u001b[0m", "
u001b[0;37mOS\u001b[0m: \u001b[0;32mLinux\u001b[0m", "\u001b[0;37mCGROUPS_CPU\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCGROUPS_CPUACCT\u001b[0m:
\u001b[0;32menabled\u001b[0m", "\u001b[0;37mCGROUPS_CPUSET\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCGROUPS_DEVICES\u001b[0m: \u001b[0;32menabled
\u001b[0m", "\u001b[0;37mCGROUPS_FREEZER\u001b[0m: \u001b[0;32menabled\u001b[0m", "\u001b[0;37mCGROUPS_MEMORY\u001b[0m: \u001b[0;32menabled\u001b[0m"]}
to retry, use: --limit @/home/user/kubeadm-devbox.retry
PLAY RECAP ***************************************************************************************************************************************************
localhost : ok=6 changed=1 unreachable=0 failed=1