---
# System prepended metadata

title: How To install kubespray

---


# How To install kubespray

## Set key for windows
cat id_rsa.pub | ssh root@172.30.xx.xxx "cat >> ~/.ssh/authorized_keys"

## Update Master and Node
```cmake=
yum update -y && yum upgrade -y
```
## Install zsh
```cmake=
yum install zsh -y && yum install  wget git -y
chsh -s /bin/zsh root

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

source ~/.zshrc
## edit ~/.zshrc
vi ~/.zshrc
ZSH_THEME='risto'
plugins=(git extract web-search yum git-extras docker vagrant zsh-autosuggestions)
```

## Update hosts file for Master
```cmake=
cat >>/etc/hosts<<EOF
172.30.216.121 k8s-master
172.30.216.131 worker-node1
172.30.216.132 worker-node2
EOF
```

## Disable swap
```cmake=
swapoff -a
sed -i 's/^\(.*swap.*\)$/#\1/' /etc/fstab 
#s
vi /etc/fstab
# /dev/mapper/centos-swap swap swap defaults 0 0
```

## Disable SELinux

```cmake=
setenforce 0
sed -i --follow-symlinks 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
```


## Stop and disable firewalld
```cmake=
firewall-cmd --permanent --add-port=6443/tcp &&firewall-cmd --permanent --add-port=2379-2380/tcp &&   firewall-cmd --permanent --add-port=10250/tcp &&firewall-cmd --permanent --add-port=10251/tcp && firewall-cmd --permanent --add-port=10252/tcp && firewall-cmd --permanent --add-port=10255/tcp 

firewall-cmd --reload
systemctl stop firewalld
modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

```



## Add sysctl settings
echo "[TASK 6] Add sysctl settings"
```cmake=
cat >>/etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
```

## Server manager Genkey and Map master , node
https://github.com/kubernetes-sigs/kubespray?fbclid=IwAR3ZPJ83p94WhmWcVF3YaI_aI5AKU1A4qBtc2oDfXVKHmGHd6V5uM2eTd9Y

```cmake=
ssh-keygen -t rsa

ssh-copy-id 192.168.xx.xx
```

## install python3 :metal:
```cmake=
sudo yum -y install https://centos7.iuscommunity.org/ius-release.rpm

yum install -y python3-pip
pip3 install --upgrade pip
which python3
```

## install kubespray
```cmake=
git clone https://github.com/kubernetes-sigs/kubespray.git

cd kubespray
 
pip install -r requirements.txt

cp -rfp inventory/sample inventory/app-cluster

declare -a IPS=(192.168.7.50 192.168.7.51 192.168.7.101 192.168.7.102 192.168.7.103)

CONFIG_FILE=inventory/app-cluster/inventory.yml python3 contrib/inventory_builder/inventory.py ${IPS[@]}

ansible-playbook -i inventory/app-cluster/inventory.ini --become --become-user=root cluster.yml -b -v

```

## edit file inventory.ini part inventory/app-cluster

```yaml=
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.

[all]
 master-01 ansible_host=192.168.7.50   ip=192.168.7.50
 master-02 ansible_host=192.168.7.51   ip=192.168.7.51
 worker-node1 ansible_host=192.168.7.101   ip=192.168.7.101
 worker-node2 ansible_host=192.168.7.102   ip=192.168.7.102
 worker-node3 ansible_host=192.168.7.103   ip=192.168.7.103 

# ## configure a bastion host if your nodes are not directly reachable
# bastion ansible_host=x.x.x.x ansible_user=some_user

[kube-master]
 master-01
 master-02

[etcd]
 master-01
 master-02


[kube-node]
 worker-node1
 worker-node2
 worker-node3 

[calico-rr]

[k8s-cluster:children]
kube-master
kube-node
calico-rr


```

## get kubernetes-dashboard


## Reset 
```cmake=
ansible-playbook -i inventory/mycluster/inventory.yml reset.yml

rm -rf usr/local/bin/etcdc (master)

/usr/local/bin/etcdctl
```
