Allow for overriding dns resolvers in install-kubernetes

By default kubernetes wants to use the local resolvers on the host
system. But in many cases the local resolver may be 127.0.0.1 which is a
different localhost on the host system then in the container network
namespaces. To address this disconnect you can supply a different
resolv.conf with a list of nameservers to use instead. Add support for
this.

Note that the test currently only uses ipv4 resolvers because by default
k8s has no support for ipv6.

Change-Id: I3c0d7d88613e2c9112e809f036aef3dfeaf7ab72
This commit is contained in:
Clark Boylan 2019-08-21 09:36:27 -07:00
parent 04f4cecaec
commit 5c089bf032
6 changed files with 54 additions and 1 deletions

View File

@ -11,3 +11,9 @@ An ansible role to install kubernetes.
:default: latest
The version of Minikube to install.
.. zuul:rolevar:: minikube_dns_resolvers
:default: []
List of dns resolvers to configure in k8s. Use this to override the
resolvers that are found by default.

View File

@ -1,2 +1,3 @@
install_kubernetes_with_cluster: True
minikube_version: latest
minikube_dns_resolvers: []

View File

@ -32,9 +32,25 @@
state: directory
mode: 0755
- name: Default args
set_fact:
minikube_args: ""
- name: Configure dns options if set
block:
- name: Write resolv.conf
template:
src: resolv.conf.j2
dest: "{{ ansible_user_dir }}/.minikube/k8s_resolv.conf"
mode: "0444"
- name: Set extra kube setttings
set_fact:
minikube_args: "--extra-config=kubelet.resolv-conf={{ ansible_user_dir }}/.minikube/k8s_resolv.conf"
when: minikube_dns_resolvers
- name: Start Minikube
become: yes
command: /tmp/minikube --vm-driver=none start
command: "/tmp/minikube --vm-driver=none start {{ minikube_args }}"
environment:
MINIKUBE_WANTUPDATENOTIFICATION: false
MINIKUBE_WANTREPORTERRORPROMPT: false

View File

@ -0,0 +1,3 @@
{% for x in minikube_dns_resolvers %}
nameserver {{ x }}
{% endfor %}

View File

@ -0,0 +1,8 @@
- hosts: primary
name: Install kubernetes with minikube
roles:
- role: install-kubernetes
vars:
minikube_dns_resolvers:
- '1.1.1.1'
- '8.8.8.8'

View File

@ -24,11 +24,30 @@
- name: builder
label: ubuntu-bionic
- job:
name: zuul-jobs-test-install-kubernetes
description: |
Test the install-kubernetes role
This job tests changes to the install-kubernetes roles. It
is not meant to be used directly but rather run on changes to
roles in the zuul-jobs repo.
files:
- roles/install-docker/.*
- roles/install-kubernetes/.*
- test-playbooks/install-kubernetes.yaml
run: test-playbooks/install-kubernetes.yaml
nodeset:
nodes:
- name: primary
label: ubuntu-bionic
# List all the jobs in this file.
- project:
check:
jobs: &id001
- zuul-jobs-test-registry
- zuul-jobs-test-install-kubernetes
gate:
jobs: *id001