-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes-nodes
173 lines (149 loc) · 4.58 KB
/
kubernetes-nodes
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
/etc/systemd/network/10-static.network
[Match]
Name=eth1
[Network]
Address=192.168.0.5/24
#---------------------------------------------------
sudo mkdir -p /etc/kubernetes/ssl
sudo cp /home/core/* /etc/kubernetes/ssl
/etc/kubernetes/ssl/ca.pem
/etc/kubernetes/ssl/node1-worker.pem
/etc/kubernetes/ssl/node1-worker-key.pem
sudo chmod 600 /etc/kubernetes/ssl/*-key.pem
sudo chown root:root /etc/kubernetes/ssl/*-key.pem
cd /etc/kubernetes/ssl/
sudo ln -s node1-worker.pem worker.pem
sudo ln -s node1-worker-key.pem worker-key.pem
#------------------------------------------------------
sudo mkdir -p /etc/flannel/
sudo bash -c "cat > /etc/flannel/options.env <<__EOF__
FLANNELD_IFACE=eth1
FLANNELD_ETCD_ENDPOINTS=http://192.168.0.2:2379,http://192.168.0.3:2379,http://192.168.0.4:2379
__EOF__"
sudo mkdir -p /etc/systemd/system/flanneld.service.d
sudo bash -c "cat > /etc/systemd/system/flanneld.service.d/40-ExecStartPre-symlink.conf <<__EOF__
[Service]
ExecStartPre=/usr/bin/ln -sf /etc/flannel/options.env /run/flannel/options.env
__EOF__"
sudo mkdir -p /etc/systemd/system/docker.service.d/
sudo bash -c "cat > /etc/systemd/system/docker.service.d/40-flannel.conf <<__EOF__
[Unit]
Requires=flanneld.service
After=flanneld.service
[Service]
EnvironmentFile=/etc/kubernetes/cni/docker_opts_cni.env
__EOF__"
sudo mkdir -p /etc/kubernetes/cni/net.d
sudo bash -c "cat > /etc/kubernetes/cni/docker_opts_cni.env <<__EOF__
DOCKER_OPT_BIP=""
DOCKER_OPT_IPMASQ=""
__EOF__"
sudo bash -c 'cat > /etc/kubernetes/cni/net.d/10-flannel.conf <<__EOF__
{
"name": "podnet",
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
}
__EOF__'
#----------------------------
sudo mkdir /etc/kubernetes/manifests
#-----kubelet----------
sudo bash -c 'cat > /etc/systemd/system/kubelet.service <<__EOF__
[Service]
Environment=KUBELET_IMAGE_TAG=v1.6.6_coreos.1
Environment="RKT_RUN_ARGS=--uuid-file-save=/var/run/kubelet-pod.uuid \
--volume dns,kind=host,source=/etc/resolv.conf \
--mount volume=dns,target=/etc/resolv.conf \
--volume var-log,kind=host,source=/var/log \
--mount volume=var-log,target=/var/log"
ExecStartPre=/usr/bin/mkdir -p /etc/kubernetes/manifests
ExecStartPre=/usr/bin/mkdir -p /var/log/containers
ExecStartPre=-/usr/bin/rkt rm --uuid-file=/var/run/kubelet-pod.uuid
ExecStart=/usr/lib/coreos/kubelet-wrapper \
--api-servers=https://192.168.0.2 \
--cni-conf-dir=/etc/kubernetes/cni/net.d \
--network-plugin=cni \
--container-runtime=docker \
--register-node=true \
--allow-privileged=true \
--pod-manifest-path=/etc/kubernetes/manifests \
--hostname-override=192.168.0.8 \
--cluster_dns=10.254.0.100 \
--cluster_domain=cluster.local \
--kubeconfig=/etc/kubernetes/worker-kubeconfig.yaml \
--tls-cert-file=/etc/kubernetes/ssl/worker.pem \
--tls-private-key-file=/etc/kubernetes/ssl/worker-key.pem
ExecStop=-/usr/bin/rkt stop --uuid-file=/var/run/kubelet-pod.uuid
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
__EOF__'
#----------------------------
sudo bash -c "cat > /etc/kubernetes/manifests/kube-proxy.yaml <<__EOF__
apiVersion: v1
kind: Pod
metadata:
name: kube-proxy
namespace: kube-system
spec:
hostNetwork: true
containers:
- name: kube-proxy
image: quay.io/coreos/hyperkube:v1.6.6_coreos.1
command:
- /hyperkube
- proxy
- --master=https://192.168.0.2
- --kubeconfig=/etc/kubernetes/worker-kubeconfig.yaml
securityContext:
privileged: true
volumeMounts:
- mountPath: /etc/ssl/certs
name: "ssl-certs"
- mountPath: /etc/kubernetes/worker-kubeconfig.yaml
name: "kubeconfig"
readOnly: true
- mountPath: /etc/kubernetes/ssl
name: "etc-kube-ssl"
readOnly: true
volumes:
- name: "ssl-certs"
hostPath:
path: "/usr/share/ca-certificates"
- name: "kubeconfig"
hostPath:
path: "/etc/kubernetes/worker-kubeconfig.yaml"
- name: "etc-kube-ssl"
hostPath:
path: "/etc/kubernetes/ssl"
__EOF__"
#-------------------------
sudo bash -c "cat > /etc/kubernetes/worker-kubeconfig.yaml <<__EOF__
apiVersion: v1
kind: Config
clusters:
- name: local
cluster:
certificate-authority: /etc/kubernetes/ssl/ca.pem
users:
- name: kubelet
user:
client-certificate: /etc/kubernetes/ssl/worker.pem
client-key: /etc/kubernetes/ssl/worker-key.pem
contexts:
- context:
cluster: local
user: kubelet
name: kubelet-context
current-context: kubelet-context
__EOF__"
#------------------
sudo systemctl daemon-reload
sudo systemctl start flanneld
sudo systemctl enable flanneld
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl enable kubelet