-
Notifications
You must be signed in to change notification settings - Fork 14
/
promethues-grafana
179 lines (126 loc) · 5.28 KB
/
promethues-grafana
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#####################RUN ON MASTER ONLY###################
#!/bin/bash
# Disable swap
swapoff -a
cp /etc/fstab /etc/fstab.backup
# Comment /etc/fstab
# https://unix.stackexchange.com/questions/295537/how-do-i-comment-lines-in-fstab-using-sed
# https://stackoverflow.com/questions/8488253/how-to-force-cp-to-overwrite-without-confirmation/38649556
awk '/[/]swap/{$0="#"$0} 1' /etc/fstab >/etc/fstab.tmp && yes | mv /etc/fstab.tmp /etc/fstab 2>&1 > /dev/null
### Install Docker and Kubernetes on all servers ###
#Disable SELinux.
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
#Enable the br_netfilter module for cluster communication.
modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
# Ensure that the Docker dependencies are satisfied.
yum install -y yum-utils device-mapper-persistent-data lvm2
# Add the Docker repo and install Docker.
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce-18.06.1.ce-3.el7 2>&1 > /dev/null
#Set the cgroup driver for Docker to systemd, then reload systemd, enable and start Docker
sed -i '/^ExecStart/ s/$/ --exec-opt native.cgroupdriver=systemd/' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl enable docker --now
# Add the repo for Kubernetes.
cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
# Install Kubernetes 1.11.3
yum install -y kubelet-1.11.3 kubeadm-1.11.3 kubectl-1.11.3 kubernetes-cni-0.6.0 --disableexcludes=kubernetes
# Start and enable the Kubernetes service
systemctl start kubelet && systemctl enable kubelet
# Create the k8s.conf file
cat << EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
# END
### Do This part Manually ###
# 1. Create kube-config.yml:
vim kube-config.yml
Add the following to kube-config.yml:
apiVersion: kubeadm.k8s.io/v1alpha1
kind:
kubernetesVersion: "v1.11.3"
networking:
podSubnet: 10.244.0.0/16
apiServerExtraArgs:
service-node-port-range: 8000-31274
# 2. Initialize Kubernetes
kubeadm init --config kube-config.yml
# 3. Copy admin.conf to your home directory
mkdir -p $HOME/.kube
# 4. Copy
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
# 5. Install flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
# Bug Fixed
############################################################
### Only Required incase of error or lines not present ###
# Patch flannel
vim /etc/kubernetes/manifests/kube-controller-manager.yaml
#Add the following to kube-controller-manager.yaml (if absent):
# add these if absent under ---> -kube-controller-manager
--allocate-node-cidrs=true
--cluster-cidr=10.244.0.0/16
############################################################
# 6. Reolad kubelete
systemctl restart kubelet
############################################### Worker Nodes #####################################################################
#!/bin/bash
# Disable swap
swapoff -a
cp /etc/fstab /etc/fstab.backup
# Comment /etc/fstab
# https://unix.stackexchange.com/questions/295537/how-do-i-comment-lines-in-fstab-using-sed
# https://stackoverflow.com/questions/8488253/how-to-force-cp-to-overwrite-without-confirmation/38649556
awk '/[/]swap/{$0="#"$0} 1' /etc/fstab >/etc/fstab.tmp && yes | mv /etc/fstab.tmp /etc/fstab 2>&1 > /dev/null
### Install Docker and Kubernetes on all servers ###
#Disable SELinux.
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
#Enable the br_netfilter module for cluster communication.
modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
# Ensure that the Docker dependencies are satisfied.
yum install -y yum-utils device-mapper-persistent-data lvm2
# Add the Docker repo and install Docker.
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce-18.06.1.ce-3.el7 2>&1 > /dev/null
#Set the cgroup driver for Docker to systemd, then reload systemd, enable and start Docker
sed -i '/^ExecStart/ s/$/ --exec-opt native.cgroupdriver=systemd/' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl enable docker --now
# Add the repo for Kubernetes.
cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
# Install Kubernetes 1.11.3
yum install -y kubelet-1.11.3 kubeadm-1.11.3 kubectl-1.11.3 kubernetes-cni-0.6.0 --disableexcludes=kubernetes
# Start and enable the Kubernetes service
systemctl start kubelet && systemctl enable kubelet
# Create the k8s.conf file
cat << EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
# END