e664a0215e
Minikube provides addons and we can enable specific addons by passing the --addons arg when using minikube cli Change-Id: I8d10e3a3dde1070b5c79406285035dacb59dddc8
134 lines
3.6 KiB
YAML
134 lines
3.6 KiB
YAML
- name: Check for Minikube install
|
|
stat:
|
|
path: /tmp/minikube
|
|
register: stat_result
|
|
|
|
- name: Download Minikube
|
|
get_url:
|
|
url: https://storage.googleapis.com/minikube/releases/{{ minikube_version }}/minikube-linux-amd64
|
|
dest: /tmp/minikube
|
|
mode: 0755
|
|
when: not stat_result.stat.exists
|
|
|
|
- name: Run ensure-docker role
|
|
include_role:
|
|
name: ensure-docker
|
|
|
|
- name: Install crio
|
|
when: kubernetes_runtime == 'cri-o'
|
|
include_tasks: crio.yaml
|
|
|
|
- name: Create .kube directory
|
|
file:
|
|
path: "{{ ansible_user_dir }}/.kube"
|
|
state: directory
|
|
mode: 0755
|
|
|
|
- name: Create .kube/config file
|
|
file:
|
|
path: "{{ ansible_user_dir }}/.kube/config"
|
|
state: touch
|
|
mode: 0644
|
|
|
|
- name: Create .minikube directory
|
|
file:
|
|
path: "{{ ansible_user_dir }}/.minikube"
|
|
state: directory
|
|
mode: 0755
|
|
|
|
- name: Default args
|
|
set_fact:
|
|
extra_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:
|
|
extra_args: "--extra-config=kubelet.resolv-conf={{ ansible_user_dir }}/.minikube/k8s_resolv.conf"
|
|
when: minikube_dns_resolvers|length>0
|
|
|
|
- name: Start Minikube
|
|
become: yes
|
|
command: >-
|
|
/tmp/minikube start
|
|
--v=7
|
|
--vm-driver=none
|
|
--container-runtime={{ kubernetes_runtime }}
|
|
{{ extra_args }}
|
|
{% for _addon in ensure_kubernetes_minikube_addons %}
|
|
--addons={{ _addon }}
|
|
{% endfor %}
|
|
environment:
|
|
MINIKUBE_WANTUPDATENOTIFICATION: false
|
|
MINIKUBE_WANTREPORTERRORPROMPT: false
|
|
MINIKUBE_WANTNONEDRIVERWARNING: false
|
|
MINIKUBE_WANTKUBECTLDOWNLOADMSG: false
|
|
CHANGE_MINIKUBE_NONE_USER: true
|
|
MINIKUBE_HOME: "{{ ansible_user_dir }}"
|
|
KUBECONFIG: "{{ ansible_user_dir }}/.kube/config"
|
|
|
|
- name: Get KUBECONFIG
|
|
command: "kubectl config view"
|
|
register: kubeconfig_yaml
|
|
|
|
- name: Parse KUBECONFIG YAML
|
|
set_fact:
|
|
kube_config: "{{ kubeconfig_yaml.stdout | from_yaml }}"
|
|
|
|
- name: Ensure minikube config is owned by ansible_user
|
|
become: yes
|
|
loop: "{{ kube_config['users'] }}"
|
|
loop_control:
|
|
loop_var: zj_item
|
|
file:
|
|
path: "{{ zj_item['user']['client-key'] }}"
|
|
owner: "{{ ansible_user }}"
|
|
|
|
- name: Get cluster info
|
|
command: kubectl cluster-info
|
|
|
|
- name: Concatenate the dns resolvers
|
|
# This is a hack to solve a temp problem.
|
|
# The problem is related to the resolv conf auto-setting function of the minikube v1.10.x.
|
|
# Zuul uses ubound as a DNS caching, so the systemd resolv has localhost.
|
|
# To avoid the coreDNS loop, we specified nameservers explicitly and overrided the for the minikube.
|
|
# But the new version is appending the systemd resolv conf always. i.e. coreDNS loop.
|
|
set_fact:
|
|
dns_resolvers: "{{ minikube_dns_resolvers | join(' ') }}"
|
|
when: minikube_dns_resolvers|length>0
|
|
|
|
- name: Patch coreDNS corefile with the specified dns resolvers
|
|
command: |
|
|
kubectl patch cm coredns -n kube-system --patch="
|
|
data:
|
|
Corefile: |
|
|
.:53 {
|
|
errors
|
|
health {
|
|
lameduck 5s
|
|
}
|
|
ready
|
|
kubernetes cluster.local in-addr.arpa ip6.arpa {
|
|
pods insecure
|
|
fallthrough in-addr.arpa ip6.arpa
|
|
ttl 30
|
|
}
|
|
prometheus :9153
|
|
forward . {{ dns_resolvers }}
|
|
cache 30
|
|
loop
|
|
reload
|
|
loadbalance
|
|
}"
|
|
when: minikube_dns_resolvers|length>0
|
|
|
|
- name: Rollout coreDNS deployment
|
|
command: |
|
|
kubectl rollout restart deploy/coredns -n kube-system
|
|
when: minikube_dns_resolvers|length>0
|