Giter VIP home page Giter VIP logo

kubernetes-sigs / kubespray Goto Github PK

View Code? Open in Web Editor NEW
15.4K 319.0 6.3K 23.39 MB

Deploy a Production Ready Kubernetes Cluster

License: Apache License 2.0

Shell 6.09% Python 5.65% HCL 12.44% Smarty 0.14% Makefile 0.09% Dockerfile 0.33% HTML 0.09% Ruby 0.15% Jinja 75.03%
kubernetes-cluster ansible kubernetes high-availability bare-metal gce aws kubespray k8s-sig-cluster-lifecycle hacktoberfest

kubespray's Introduction

Deploy a Production Ready Kubernetes Cluster

Kubernetes Logo

If you have questions, check the documentation at kubespray.io and join us on the kubernetes slack, channel #kubespray. You can get your invite here

  • Can be deployed on AWS, GCE, Azure, OpenStack, vSphere, Equinix Metal (bare metal), Oracle Cloud Infrastructure (Experimental), or Baremetal
  • Highly available cluster
  • Composable (Choice of the network plugin for instance)
  • Supports most popular Linux distributions
  • Continuous integration tests

Quick Start

Below are several ways to use Kubespray to deploy a Kubernetes cluster.

Ansible

Usage

Install Ansible according to Ansible installation guide then run the following steps:

# Copy ``inventory/sample`` as ``inventory/mycluster``
cp -rfp inventory/sample inventory/mycluster

# Update Ansible inventory file with inventory builder
declare -a IPS=(10.10.1.3 10.10.1.4 10.10.1.5)
CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}

# Review and change parameters under ``inventory/mycluster/group_vars``
cat inventory/mycluster/group_vars/all/all.yml
cat inventory/mycluster/group_vars/k8s_cluster/k8s-cluster.yml

# Clean up old Kubernetes cluster with Ansible Playbook - run the playbook as root
# The option `--become` is required, as for example cleaning up SSL keys in /etc/,
# uninstalling old packages and interacting with various systemd daemons.
# Without --become the playbook will fail to run!
# And be mind it will remove the current kubernetes cluster (if it's running)!
ansible-playbook -i inventory/mycluster/hosts.yaml  --become --become-user=root reset.yml

# Deploy Kubespray with Ansible Playbook - run the playbook as root
# The option `--become` is required, as for example writing SSL keys in /etc/,
# installing packages and interacting with various systemd daemons.
# Without --become the playbook will fail to run!
ansible-playbook -i inventory/mycluster/hosts.yaml  --become --become-user=root cluster.yml

Note: When Ansible is already installed via system packages on the control node, Python packages installed via sudo pip install -r requirements.txt will go to a different directory tree (e.g. /usr/local/lib/python2.7/dist-packages on Ubuntu) from Ansible's (e.g. /usr/lib/python2.7/dist-packages/ansible still on Ubuntu). As a consequence, the ansible-playbook command will fail with:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

This likely indicates that a task depends on a module present in requirements.txt.

One way of addressing this is to uninstall the system Ansible package then reinstall Ansible via pip, but this not always possible and one must take care regarding package versions. A workaround consists of setting the ANSIBLE_LIBRARY and ANSIBLE_MODULE_UTILS environment variables respectively to the ansible/modules and ansible/module_utils subdirectories of the pip installation location, which is the Location shown by running pip show [package] before executing ansible-playbook.

A simple way to ensure you get all the correct version of Ansible is to use the pre-built docker image from Quay. You will then need to use bind mounts to access the inventory and SSH key in the container, like this:

git checkout v2.24.1
docker pull quay.io/kubespray/kubespray:v2.24.1
docker run --rm -it --mount type=bind,source="$(pwd)"/inventory/sample,dst=/inventory \
  --mount type=bind,source="${HOME}"/.ssh/id_rsa,dst=/root/.ssh/id_rsa \
  quay.io/kubespray/kubespray:v2.24.1 bash
# Inside the container you may now run the kubespray playbooks:
ansible-playbook -i /inventory/inventory.ini --private-key /root/.ssh/id_rsa cluster.yml

Collection

See here if you wish to use this repository as an Ansible collection

Vagrant

For Vagrant we need to install Python dependencies for provisioning tasks. Check that Python and pip are installed:

python -V && pip -V

If this returns the version of the software, you're good to go. If not, download and install Python from here https://www.python.org/downloads/source/

Install Ansible according to Ansible installation guide then run the following step:

vagrant up

Documents

Supported Linux Distributions

  • Flatcar Container Linux by Kinvolk
  • Debian Bookworm, Bullseye, Buster
  • Ubuntu 20.04, 22.04
  • CentOS/RHEL 7, 8, 9
  • Fedora 37, 38
  • Fedora CoreOS (see fcos Note)
  • openSUSE Leap 15.x/Tumbleweed
  • Oracle Linux 7, 8, 9
  • Alma Linux 8, 9
  • Rocky Linux 8, 9
  • Kylin Linux Advanced Server V10 (experimental: see kylin linux notes)
  • Amazon Linux 2 (experimental: see amazon linux notes)
  • UOS Linux (experimental: see uos linux notes)
  • openEuler (experimental: see openEuler notes)

Note: Upstart/SysV init based OS types are not supported.

Supported Components

Container Runtime Notes

  • Supported Docker versions are 18.09, 19.03, 20.10, 23.0 and 24.0. The recommended Docker version is 24.0. Kubelet might break on docker's non-standard version numbering (it no longer uses semantic versioning). To ensure auto-updates don't break your cluster look into e.g. the YUM versionlock plugin or apt pin).
  • The cri-o version should be aligned with the respective kubernetes version (i.e. kube_version=1.20.x, crio_version=1.20)

Requirements

  • Minimum required version of Kubernetes is v1.27
  • Ansible v2.14+, Jinja 2.11+ and python-netaddr is installed on the machine that will run Ansible commands
  • The target servers must have access to the Internet in order to pull docker images. Otherwise, additional configuration is required (See Offline Environment)
  • The target servers are configured to allow IPv4 forwarding.
  • If using IPv6 for pods and services, the target servers are configured to allow IPv6 forwarding.
  • The firewalls are not managed, you'll need to implement your own rules the way you used to. in order to avoid any issue during deployment you should disable your firewall.
  • If kubespray is run from non-root user account, correct privilege escalation method should be configured in the target servers. Then the ansible_become flag or command parameters --become or -b should be specified.

Hardware: These limits are safeguarded by Kubespray. Actual requirements for your workload can differ. For a sizing guide go to the Building Large Clusters guide.

  • Master
    • Memory: 1500 MB
  • Node
    • Memory: 1024 MB

Network Plugins

You can choose among ten network plugins. (default: calico, except Vagrant uses flannel)

  • flannel: gre/vxlan (layer 2) networking.

  • Calico is a networking and network policy provider. Calico supports a flexible set of networking options designed to give you the most efficient networking across a range of situations, including non-overlay and overlay networks, with or without BGP. Calico uses the same engine to enforce network policy for hosts, pods, and (if using Istio and Envoy) applications at the service mesh layer.

  • cilium: layer 3/4 networking (as well as layer 7 to protect and secure application protocols), supports dynamic insertion of BPF bytecode into the Linux kernel to implement security services, networking and visibility logic.

  • weave: Weave is a lightweight container overlay network that doesn't require an external K/V database cluster. (Please refer to weave troubleshooting documentation).

  • kube-ovn: Kube-OVN integrates the OVN-based Network Virtualization with Kubernetes. It offers an advanced Container Network Fabric for Enterprises.

  • kube-router: Kube-router is a L3 CNI for Kubernetes networking aiming to provide operational simplicity and high performance: it uses IPVS to provide Kube Services Proxy (if setup to replace kube-proxy), iptables for network policies, and BGP for ods L3 networking (with optionally BGP peering with out-of-cluster BGP peers). It can also optionally advertise routes to Kubernetes cluster Pods CIDRs, ClusterIPs, ExternalIPs and LoadBalancerIPs.

  • macvlan: Macvlan is a Linux network driver. Pods have their own unique Mac and Ip address, connected directly the physical (layer 2) network.

  • multus: Multus is a meta CNI plugin that provides multiple network interface support to pods. For each interface Multus delegates CNI calls to secondary CNI plugins such as Calico, macvlan, etc.

  • custom_cni : You can specify some manifests that will be applied to the clusters to bring you own CNI and use non-supported ones by Kubespray. See tests/files/custom_cni/README.md and tests/files/custom_cni/values.yamlfor an example with a CNI provided by a Helm Chart.

The network plugin to use is defined by the variable kube_network_plugin. There is also an option to leverage built-in cloud provider networking instead. See also Network checker.

Ingress Plugins

  • nginx: the NGINX Ingress Controller.

  • metallb: the MetalLB bare-metal service LoadBalancer provider.

Community docs and resources

Tools and projects on top of Kubespray

CI Tests

Build graphs

CI/end-to-end tests sponsored by: CNCF, Equinix Metal, OVHcloud, ELASTX.

See the test matrix for details.

kubespray's People

Contributors

ant31 avatar atoms avatar bogdando avatar bradbeam avatar chadswen avatar champtar avatar codablock avatar cristicalin avatar electrocucaracha avatar eppo avatar erikjiang avatar floryut avatar hafe avatar hswong3i avatar k8s-ci-robot avatar liupeng0518 avatar luckysb avatar mattymo avatar miouge1 avatar mirwan avatar mrfreezeex avatar mzaian avatar oomichi avatar riverzhang avatar rsmitty avatar smana avatar torvitas avatar vannten avatar woopstar avatar yankay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kubespray's Issues

Resources manifests/yaml backup

Currently, the script sends all manifests to master[0] in /etc/k8s/manifestsand then use kubectl to create the resources.
I think we all agree that is better to use API so the question is what do we do about resource manifests?

  1. Use API only, the manifests don;t need to be stored
  2. Use API only and store manifests in the deploy machine
  3. Use API only and store manifests in one of the masters
  4. (complete)

From my side

  • I like to see the manifests so not the 1.
  • 2 is fine, but deploy machine can be any. And if someone else from the team deploy, I may not have access to the manifests.
  • I like 3 :), @Smana I know you don't, can you explain why?

Configure firewall.

I see two options:

  1. configure with ansible the firewall
  2. Create a 'firewall' controller daemon that check services and ingress

Don't run etcd as pod

I had an issue on reboot with etcd as pod.

It looks like kubelet continue to try restarting same pods, and pods failed to start because etcd was not 'on'.

We should rollback and use an etcd not-managed by kubernetes.

Remove systemd depedencie

Using systemd unit should be optionnal.

This include rework on following roles:

  • etcd
  • dnsmasq
  • calico-node
  • kubelet

apps seem to fail because of unicode in templates

This is more for questions to @ant31 and @Smana.

I'm trying to use the apps (kube-dns, and others). I'm getting errors with all of them because the files to be fed into kubectl have unicode string in them. The problem appears to be that python structure dumps into the kube templates causes u'ddd' style unicode string. This isn't supported by kubectl. I've found a fix for them, but they will hit pretty much all of the k8s-XXX modules. I've added to_nice_json to many of the vars for printing into the files.

I was wondering if you have this working or haven't tried it recently.

initial deployment fails with multiple masters

Currently, the deployment fails at the first deployment.
The apiserver is restarted multiple times and when the handlers are played i have the following output for an unknown reason:

NOTIFIED: [kubernetes/master | restart kube-apiserver] ************************ 
failed: [node2] => {"failed": true}
msg: Job for kube-apiserver.service failed. See 'systemctl status kube-apiserver.service' and 'journalctl -xn' for details.

The logs don't help very much

Jan 24 15:29:54 kubenode2 kube-apiserver[4192]: [restful] 2016/01/24 15:29:54 log.go:30: [restful/swagger] listing is av
Jan 24 15:29:54 kubenode2 kube-apiserver[4192]: [restful] 2016/01/24 15:29:54 log.go:30: [restful/swagger] https://10.11
Jan 24 15:29:55 kubenode2 kube-apiserver[4192]: F0124 15:29:55.343958    4192 controller.go:80] Unable to perform initia
Jan 24 15:29:55 kubenode2 systemd[1]: kube-apiserver.service: main process exited, code=exited, status=255/n/a
Jan 24 15:29:55 kubenode2 systemd[1]: Failed to start Kubernetes API Server.
Jan 24 15:29:55 kubenode2 systemd[1]: Unit kube-apiserver.service entered failed state.

I guess the error is caused by a missing controller-manager but i'm not sure

using ansible_default_ipv4 cause issues

In the file /etc/network-environment
The default ipv4 in took from the first interface only. But it should be possible to set ip from differents interface

DEFAULT_IPV4=

Fail with sudoer user

failed: [10.206.41.5 -> localhost] => {"cmd": "rsync --delay-updates -F --compress --times --rsh 'ssh -S none -o StrictHostKeyChecking=no' --out-format='<>%i %n%L' "/tmp/releases/kubernetes/bin/kubelet" "[email protected]:/usr/local/bin/kubelet"", "failed": true, "rc": 23}
msg: rsync: mkstemp "/usr/local/bin/.kubelet.kPJDLA" failed: Permission denied (13)

ha master: kubernetes service has only only one endpoint

I just notice that the kubernetes service only have one endpoint in a multi master architecture.

Name:           kubernetes
Namespace:      default
Labels:         component=apiserver,provider=kubernetes
Selector:       <none>
Type:           ClusterIP
IP:         10.233.0.1
Port:           <unnamed>   443/TCP
Endpoints:      10.115.99.41:443
Session Affinity:   None
No events.

Document ansible usage

Some users use ansible for the first time, I think a quick note/doc-link about options and configuration would be good.

Automated tests : tasks sequence

Below is a list of tasks in order to automate cluster deployment tests :

  • Test on the main linux distribs :
    • Fedora
    • Centos 7
    • RedHat 7
    • Ubuntu 1404
    • Ubuntu 1510
    • Debian 8
  • One test per network plugin
  • Idealy a cluster will be composed of
    • a master (master components only)
    • a master with node components (handles workloads)
    • a node

Test sequence:

  • Cluster deployment
  • Check all nodes ready
  • Run a replica controller composed of 2 pods
kubectl run test --image=busybox --replicas=2 --command -- tail -f /dev/null
replicationcontroller "test" created
  • Check that pods ip addresses are in the configured subnet
kubectl describe po test-34ozs | grep ^IP
IP:             10.233.16.2

kubectl exec test-34ozs -- ip a show dev eth0
8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue
    link/ether 02:42:0a:e9:2b:03 brd ff:ff:ff:ff:ff:ff
    inet 10.233.16.2/24 scope global eth0
  • Ping between pods
  • Deploy the kubedns app and browse the kubernetes api using the service name as follows
kubectl exec test-f31yx -- curl -k -u kube:changeme https://kubernetes

Use systemd as the unique init system

I think it would be easier to manage only systemd init linux distribs.
All the main linux distribs have made that choice, even ubuntu is switching to it.

@ant31 : what is your opinion ? is it possible to use a systemd OS with travis ?

Kubelet on masters?

I propose to run kubelet on all nodes. It will allow to use pod manifests to bootstrap services like etcd.

---   
- hosts: k8s-cluster
 roles: 
    - { role: docker, tags: docker }
    - { role: kubernetes/kubelet, tags: kubelet }
    - { role: etcd, tags: etcd }  
    - { role: dnsmasq, tags: dnsmasq }
    - { role: network_plugin, tags: ['calico', 'flannel', 'network'] }

- hosts: k8s-node
  roles:
    - { role: kubernetes/node, tags: node }

- hosts: kube-master
  roles:
    - { role: kubernetes/master, tags: master }

Don't run apiserver as pod

We noticed that it was tricky to notify the apiserver about changes (e.g. add when a new node is added #47 ).
We've decided that core kubernetes components like etcd or apiserver should be running as host services.

resolve all python dependencies

fatal: [node1] => Failed to template {{ kube_service_addresses|ipaddr('net')|ipaddr(1)|ipaddr('address') }}: The ipaddr filter requires python-netaddr be installed on the ansible controller

Remove downloader host

We faced issues with synchronize module and using 'copy' had too much constraint.

I propose that each nodes download their dependencies, it will then remove the need to copy/rsync binaries from node to node.

I'll probably work again on the 'downloader' host later as it can be usefull in somecase (later)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.