Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Calico with Mesos and Kubernetes integrated #1521

Merged
merged 28 commits into from
Jun 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
50a6b65
GCE has dedicated workers for kubernetes
Zogg Dec 1, 2015
8f276fe
Kubernetes-with-mesos ansible playbook
Zogg Dec 1, 2015
3586930
patch ansible's 'kube' state
Zogg Dec 21, 2015
ab0e723
Use new kubernetes roles in sample ansible playbook
Zogg Dec 21, 2015
b79aa5e
Calico working with mesos
Zogg Jan 13, 2016
039f59f
Calico ip pools must be added before calico is started
Zogg Jan 14, 2016
a36a6a3
Allow GCE to route ipip traffic in internal network
Zogg Jan 14, 2016
3cbd090
Use packaged calico
Zogg Jan 21, 2016
da23949
dont forget mesos modules config
Zogg Jan 21, 2016
460ec46
Update with latest from mantl-kubernetes repo
Zogg Jan 27, 2016
ff7d65e
newer calico plugin
Zogg Jan 27, 2016
2bb3df8
Better ansible roles usage/separation
Zogg Jan 27, 2016
a3f375c
Calico fixes
Zogg Jan 29, 2016
1ce05e8
Calico plugin conf
Zogg Jan 29, 2016
94c9edb
k8s dont need environment vars files in systemd
Zogg Jan 29, 2016
c2db75c
Calico-kube integration
Zogg Feb 3, 2016
0bb9ac5
Calico plugins packaged into rpm
Zogg Feb 3, 2016
0387f69
Merge cleanup
Zogg Feb 10, 2016
414b8e4
Proper calico rpm repo
Zogg Feb 16, 2016
6f79c17
Share calico profile between kube and mesos
Zogg Feb 16, 2016
6f467e4
Cleanup
Zogg Feb 16, 2016
de4f5b6
Use mesos 0.27.1 by default
Zogg Mar 16, 2016
50fdbc7
Use Marathon 0.15.3 by default
Zogg Mar 16, 2016
dba08f4
Testing with marathon 1.0.0-RC1 and mesos .27
Zogg Apr 12, 2016
383d7f8
Remove MESOS_ADVERTISE_IP from mesos-agent configuration
ChrisAubuchon May 25, 2016
5cc276e
fixes after rebase
Zogg Jun 1, 2016
41c3000
Merge branch 'master' of github.com:CiscoCloud/microservices-infrastr…
Zogg Jun 9, 2016
ddc293c
Calico enabled by default
Zogg Jun 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions group_vars/all/kubernetes_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ kube_users:
role: admin

# Select which network manager to use. After choosing, edit kubernetes.yml file and include aproriate roles.
# network: calico
network: flannel
network: calico
#network: flannel

# Kubernetes cluster name, also will be used as DNS domain
cluster_name: cluster.local

# Enable to leverage some unique features of a specific cloud provider.
enable_cloud_provider: false

# Only OpenStack provider is currently supported.
cloud_provider: openstack

cloud_provider_config: /etc/kubernetes/cloud-config

# Kubernetes internal network for services, unused block of space.
kube_service_addresses: 10.254.0.0/16

Expand Down
1 change: 1 addition & 0 deletions library/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def main():
resource=dict(),
label=dict(),
server=dict(),
api_version=dict(default='v1', choices=['v1', 'v1beta3']),
force=dict(default=False, type='bool'),
all=dict(default=False, type='bool'),
log_level=dict(default=0, type='int'),
Expand Down
6 changes: 4 additions & 2 deletions roles/calico/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
calico_version: 0.15.0

calico_image: calico/node
calico_image_tag: v0.9.0
calico_image_tag: v{{ calico_version }}

bintray_baseurl: "https://bintray.com/artifact/download/asteris"
calico_binary: "{{ bintray_baseurl }}/calico/calicoctl/calicoctl"
calico_binary: "{{ bintray_baseurl }}/mantl-rpm/calico-{{ calico_version }}-1.x86_64.rpm"

etcd_service_name: etcd.service.{{ consul_dns_domain }}
etcd_client_port: 2379
Expand Down
26 changes: 26 additions & 0 deletions roles/calico/files/modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"libraries": [
{
"file": "/usr/local/lib/mesos/libmesos_network_isolator.so",
"modules": [
{
"name": "com_mesosphere_mesos_NetworkIsolator",
"parameters": [
{
"key": "isolator_command",
"value": "/usr/local/bin/calico_mesos"
},
{
"key": "ipam_command",
"value": "/usr/local/bin/calico_mesos"
}
]
},
{
"name": "com_mesosphere_mesos_NetworkHook"
}
]
}
]
}

16 changes: 6 additions & 10 deletions roles/calico/tasks/kubernetes.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
---
- name: Calico directory for plugins
- name: Calico directory for cni config
sudo: yes
file:
path: /usr/libexec/kubernetes/kubelet-plugins/net/exec/calico/
path: /etc/cni/net.d
state: directory
tags:
- calico

- name: Get calico-kubernetes plugin
- name: Calico cni config for kubernetes
sudo: yes
get_url:
url: https://github.com/projectcalico/calico-docker/releases/download/v0.5.4/calico_kubernetes
dest: /usr/libexec/kubernetes/kubelet-plugins/net/exec/calico/calico
mode: 0755
template:
src: calico-plugin.conf
dest: /etc/cni/net.d/10-calico.conf
tags:
- calico


80 changes: 22 additions & 58 deletions roles/calico/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,13 @@
---
# Ansible modprobe module doesn't provide such functionality
- name: add kernel modules to load at boot time
- name: install calico
sudo: yes
copy:
src: calico-modules.conf
dest: /etc/modules-load.d/calico-modules.conf
owner: root
group: root
mode: 0644
tags:
- calico

- name: load kernel module xt_set
sudo: yes
modprobe:
name: xt_set
yum:
name: "{{ calico_binary }}"
state: present
tags:
- calico

- name: enable kernel packet forwarding
sudo: yes
sysctl:
name: net.ipv4.ip_forward
value: 1
state: present
reload: yes
tags:
- calico

- name: download calicoctl binary
sudo: yes
get_url:
url: "{{ calico_binary }}"
dest: /usr/bin/calicoctl
mode: 0755
tags:
- calico
- bootstrap

#- name: download calicoctl bash completion script
# sudo: yes
# get_url:
# url: "{{ bintray_baseurl }}/calico/calicoctl.sh"
# dest: /etc/bash_completion.d/calicoctl.sh
# mode: 0644
# tags:
# - calico

# We can't use the Ansible standard docker module as it always starts
# containers after image was pulled
- name: ensure calico docker image is present
sudo: yes
command: /usr/bin/docker pull {{ calico_image }}:{{ calico_image_tag }}
Expand Down Expand Up @@ -107,11 +65,29 @@
tags:
- calico

- name: calico etc directory
sudo: yes
file:
path: /etc/calico
state: directory
tags:
- calico

- name: put calico-mesos integration file
sudo: yes
copy:
src: modules.json
dest: /etc/calico/modules.json
tags:
- calico

- include: openstack.yml
when: provider == 'openstack'

- include: kubernetes.yml
when: kube_build is defined
when: kube_version is defined

- include: calico-configure.yml

- name: reload calico systemd file
sudo: yes
Expand Down Expand Up @@ -144,17 +120,5 @@
failed_when: false
changed_when: false

- name: configure mesos-slave for networking integration
sudo: yes
template:
src: executor_environment_variables
dest: /etc/mesos-slave/executor_environment_variables
mode: 0644
notify:
- restart mesos agent
tags:
- calico

- meta: flush_handlers

- include: calico-configure.yml
9 changes: 9 additions & 0 deletions roles/calico/templates/calico-plugin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ng_calico-k8s-network",
"type": "calico",
"etcd_authority": "{{calico_etcdaddr}}",
"log_level": "info",
"ipam": {
"type": "calico-ipam"
}
}
13 changes: 0 additions & 13 deletions roles/calico/templates/calico.env.j2
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
# This node's IPv4 address
DEFAULT_IPV4={{ private_ipv4 }}

# IP and port of etcd instance used by Calico
ETCD_AUTHORITY={{ calico_etcdaddr }}

{% if hostvars[inventory_hostname]['role'] == 'kubeworker' %}
# The Kubernetes master IP
KUBERNETES_MASTER={{ groups[master_group_name][0] }}

KUBE_API_ROOT=https://{{ groups[master_group_name][0] }}:{{ kube_master_port }}/api/v1/
{% endif %}

# Enable Calcio IPAM
CALICO_IPAM=true
2 changes: 1 addition & 1 deletion roles/calico/templates/calico.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TimeoutStartSec=20m
ExecStartPre=-/usr/bin/docker rm -f calico-node
EnvironmentFile=/etc/default/calico
ExecStart=/usr/bin/calicoctl node --ip={{ private_ipv4 }} \
--node-image={{ calico_image }}:{{ calico_image_tag }} {% if hostvars[inventory_hostname]['role'] == 'kubeworker' %}--kubernetes{% endif %}
--node-image={{ calico_image }}:{{ calico_image_tag }}

ExecStop=/usr/bin/calicoctl node stop
ExecStopPost=-/usr/bin/docker rm -f calico-node
Expand Down
4 changes: 0 additions & 4 deletions roles/calico/templates/executor_environment_variables

This file was deleted.

2 changes: 0 additions & 2 deletions roles/kubernetes-addons/templates/skydns-rc.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ spec:
args:
- -domain={{ dns_domain }}
- -etcd-server=http://{{ private_ipv4 }}:{{ etcd_client_port }}
- -kubecfg_file=/etc/kubernetes/node.kubeconfig
volumeMounts:
- mountPath: /etc/kubernetes/
name: kube-etc
Expand All @@ -50,4 +49,3 @@ spec:
- name: kube-etc
hostPath:
path: /etc/kubernetes

3 changes: 2 additions & 1 deletion roles/kubernetes-master/templates/kube-apiserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ spec:
- --client-ca-file={{ kube_cert_dir }}/ca.crt
- --service-account-key-file={{ kube_cert_dir }}/server.key
- --basic-auth-file={{ kube_users_dir }}/known_users.csv
- --v=3
- --runtime-config=extensions/v1beta1/daemonsets=true
- --v={{kube_log_level}}
ports:
- containerPort: {{ kube_master_port }}
hostPort: {{ kube_master_port }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
- --master=http://127.0.0.1:{{ kube_insecure_port }}
- --service-account-private-key-file={{ kube_cert_dir }}/server.key
- --root-ca-file={{ kube_cert_dir }}/ca.crt
- --v={{kube_log_level}}
livenessProbe:
httpGet:
host: 127.0.0.1
Expand Down
1 change: 1 addition & 0 deletions roles/kubernetes-master/templates/kube-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
- --master=https://kubernetes.service.consul:{{ kube_master_port }}
- --kubeconfig=/etc/kubernetes/master.kubeconfig
- --proxy-mode=iptables
- --v={{kube_log_level}}
securityContext:
privileged: true
volumeMounts:
Expand Down
1 change: 1 addition & 0 deletions roles/kubernetes-master/templates/kube-scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spec:
- /hyperkube
- scheduler
- --master=http://127.0.0.1:{{ kube_insecure_port }}
- --v={{kube_log_level}}
livenessProbe:
httpGet:
host: 127.0.0.1
Expand Down
1 change: 1 addition & 0 deletions roles/kubernetes-node/templates/kube-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
- --master=https://kubernetes.service.consul:{{ kube_master_port }}
- --kubeconfig=/etc/kubernetes/node.kubeconfig
- --proxy-mode=iptables
- --v={{kube_log_level}}
securityContext:
privileged: true
volumeMounts:
Expand Down
8 changes: 8 additions & 0 deletions roles/kubernetes/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ dns_domain: "{{ cluster_name }}"
# magic will actually pick the 10th ip address in the kube_service_addresses
# range and use that.
dns_server: "{{ kube_service_addresses|ipaddr('net')|ipaddr(253)|ipaddr('address') }}"

# OpenStack cloud provider authentication variables.
os_auth_url: "{{ lookup('env','OS_AUTH_URL') }}"
os_username: "{{ lookup('env','OS_USERNAME') }}"
os_password: "{{ lookup('env','OS_PASSWORD') }}"
os_region_name: "{{ lookup('env','OS_REGION_NAME') }}"
os_tenant_id: "{{ lookup('env','OS_TENANT_ID') }}"

9 changes: 0 additions & 9 deletions roles/kubernetes/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
---
- name: evaluate first_master
add_host:
name: "{{ groups[master_group_name][0] }}"
groups: first_master
when: "master in groups and groups[master_group_name] | length > 1"
tags:
- common
- kubernetes

- name: create kubernetes config directories
sudo: yes
file:
Expand Down
13 changes: 13 additions & 0 deletions roles/kubernetes/tasks/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@
tags:
- secrets
- kubernetes

- name: create cloud provider config
sudo: yes
template:
src: cloud-config.j2
dest: "{{ cloud_provider_config }}"
owner: root
group: root
mode: 0644
when: enable_cloud_provider and cloud_provider == "openstack"
tags:
- secrets
- kubernetes
2 changes: 1 addition & 1 deletion roles/marathon/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
marathon_version: 0.13.0
marathon_version: 1.0.0_RC1
marathon_package: "marathon-{{ marathon_version }}"

marathon_zk_auth: "{% if zk_marathon_user_secret is defined %}{{ zk_marathon_user }}:{{ zk_marathon_user_secret }}@{% endif %}"
Expand Down
2 changes: 1 addition & 1 deletion roles/mesos/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
mesos_version: 0.25.0
mesos_version: 0.27.0

mesos_package: "mesos-{{ mesos_version }}"
mesos_master_package: "mesos-master-{{ mesos_version }}"
Expand Down
12 changes: 8 additions & 4 deletions roles/mesos/templates/mesos-agent.sysconfig.j2
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# common configuration
MESOS_PORT={{ mesos_follower_port }}
MESOS_ADVERTISE_IP={{ private_ipv4 }}
MESOS_IP={{ private_ipv4 }}
MESOS_HOSTNAME={{ mesos_hostname | default(inventory_hostname) }}
MESOS_HOSTNAME={{ mesos_hostname | default(inventory_hostname + ".node." + consul_dns_domain) }}
MESOS_LOG_DIR={{ mesos_log_dir }}
MESOS_EXTERNAL_LOG_FILE=/var/log/mesos/mesos-agent.log
MESOS_LOGGING_LEVEL={{ mesos_logging_level }}

Expand All @@ -21,4 +20,9 @@ MESOS_WORK_DIR={{ mesos_work_dir }}
# authentication
{% if not (do_mesos_follower_auth|bool) %}# {% endif %}MESOS_CREDENTIAL=file:///etc/sysconfig/mesos-agent-credential

EXTRA_OPTS=""
EXTRA_OPTS="{% if calico_etcdaddr is defined %}--modules=file:///etc/calico/modules.json --isolation=com_mesosphere_mesos_NetworkIsolator --hooks=com_mesosphere_mesos_NetworkHook {% endif %}"

# calico integration
{% if calico_etcdaddr is defined %}
ETCD_AUTHORITY={{ calico_etcdaddr }}
{% endif %}
Loading