-
Notifications
You must be signed in to change notification settings - Fork 2
/
kubeadm_deploy_step5.sh
871 lines (721 loc) · 22.6 KB
/
kubeadm_deploy_step5.sh
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
# kubernetes cluster setup
if you loss some k8s image , you can download from
https://hub.docker.com/u/huasuoworld
when you pull image , please be carefully
## 1. download kubernetes server-binaries
https://kubernetes.io/docs/setup/release/notes/#server-binaries
or
https://github.com/kubernetes/kubernetes/releases
master node
~~~ shell
cp kube-apiserver kube-controller-manager kube-scheduler kubectl kubelet kube-proxy /usr/bin
~~~
slave
~~~shell
cp kubectl kubelet kube-proxy /usr/bin
~~~
将 kube-apiserver kube-controller-manager kube-scheduler kubectl kubelet kube-proxy 拷贝到主节点/usr/bin, 将kubectl kubelet kube-proxy 拷贝到从节点 /usr/bin.
## 2. download etcd
https://github.com/etcd-io/etcd/releases
~~~shell
cp etcd etcdctl /usr/bin
~~~
将etcd etcdctl拷贝到 /usr/bin目录下.
## 3. download flannel
https://github.com/coreos/flannel/releases
~~~shell
cp flanneld /usr/bin
~~~
将 flanneld 拷贝到/usr/bin.
## 4. cfssl create certificate
1. Download, unpack and prepare the command line tools as shown below. Note that you may need to adapt the sample commands based on the hardware architecture and cfssl version you are using.
```json
curl -L https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 -o cfssl
chmod +x cfssl
curl -L https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -o cfssljson
chmod +x cfssljson
curl -L https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 -o cfssl-certinfo
chmod +x cfssl-certinfo
```
2. Create a directory to hold the artifacts and initialize cfssl:
```shell
mkdir cert
cd cert
../cfssl print-defaults config > config.json
../cfssl print-defaults csr > csr.json
```
3. Create a JSON config file for generating the CA file, for example, `ca-config.json`:
```json
{
"signing": {
"default": {
"expiry": "8760h"
},
"profiles": {
"kubernetes": {
"usages": [
"signing",
"key encipherment",
"server auth",
"client auth"
],
"expiry": "8760h"
}
}
}
}
```
4. Create a JSON config file for CA certificate signing request (CSR), for example, `ca-csr.json`. Be sure the replace the values marked with angle brackets with real values you want to use.
```json
{
"CN": "kubernetes",
"key": {
"algo": "rsa",
"size": 2048
},
"names":[{
"C": "<country>",
"ST": "<state>",
"L": "<city>",
"O": "<organization>",
"OU": "<organization unit>"
}]
}
```
5. Generate CA key (`ca-key.pem`) and certificate (`ca.pem`):
```shell
../cfssl gencert -initca ca-csr.json | ../cfssljson -bare ca
```
6. Create a JSON config file for generating keys and certificates for the API server as shown below. Be sure to replace the values in angle brackets with real values you want to use. The `MASTER_CLUSTER_IP` is the service cluster IP for the API server as described in previous subsection. The sample below also assumes that you are using `cluster.local` as the default DNS domain name.
```json
{
"CN": "kubernetes",
"hosts": [
"127.0.0.1",
"<MASTER_IP>",
"<MASTER_CLUSTER_IP>",
"kubernetes",
"kubernetes.default",
"kubernetes.default.svc",
"kubernetes.default.svc.cluster",
"kubernetes.default.svc.cluster.local"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [{
"C": "<country>",
"ST": "<state>",
"L": "<city>",
"O": "<organization>",
"OU": "<organization unit>"
}]
}
```
7. Generate the key and certificate for the API server, which are by default saved into file server-key.pem and server.pem respectively:
```shell
../cfssl gencert -ca=ca.pem -ca-key=ca-key.pem \
--config=ca-config.json -profile=kubernetes \
server-csr.json | ../cfssljson -bare server
```
8.Distributing Self-Signed CA Certificate
scp * root@xxx:/etc/kubernetes/cert
## 3. systemctl etcd.service
go to /usr/lib/systemd/system
```shell
[Unit]
Description=Etcd Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/etcd --config-file=/etc/kubernetes/etcd.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
```
```yaml
# This is the configuration file for the etcd server.
# Human-readable name for this member.
name: 'zoo0'
# Path to the data directory.
data-dir: /data/etcd
# List of comma separated URLs to listen on for peer traffic.
listen-peer-urls: https://192.168.1.0:2380
# List of comma separated URLs to listen on for client traffic.
listen-client-urls: https://192.168.1.0:2379
# List of this member's peer URLs to advertise to the rest of the cluster.
# The URLs needed to be a comma-separated list.
initial-advertise-peer-urls: https://192.168.1.0:2380
# List of this member's client URLs to advertise to the public.
# The URLs needed to be a comma-separated list.
advertise-client-urls: https://192.168.1.0:2379
# Initial cluster configuration for bootstrapping.
initial-cluster: zoo0=https://192.168.1.0:2380,zoo1=https://192.168.1.1:2380,zoo2=https://192.168.1.2:2380,zoo3=https://192.168.1.3:2380
# Initial cluster token for the etcd cluster during bootstrap.
initial-cluster-token: 'etcd-cluster'
# Initial cluster state ('new' or 'existing').
initial-cluster-state: 'new'
# Accept etcd V2 client requests
enable-v2: true
client-transport-security:
# Path to the client server TLS cert file.
cert-file: /etc/kubernetes/cert/server.pem
# Path to the client server TLS key file.
key-file: /etc/kubernetes/cert/server-key.pem
# Enable client cert authentication.
client-cert-auth: false
# Path to the client server TLS trusted CA cert file.
trusted-ca-file: /etc/kubernetes/cert/ca.pem
# Client TLS using generated certificates
auto-tls: false
peer-transport-security:
# Path to the peer server TLS cert file.
cert-file: /etc/kubernetes/cert/server.pem
# Path to the peer server TLS key file.
key-file: /etc/kubernetes/cert/server-key.pem
# Enable peer client cert authentication.
client-cert-auth: false
# Path to the peer server TLS trusted CA cert file.
trusted-ca-file: /etc/kubernetes/cert/ca.pem
# Peer TLS using generated certificates.
auto-tls: false
# Enable debug-level logging for etcd.
debug: false
logger: zap
# Specify 'stdout' or 'stderr' to skip journald logging even when running under systemd.
log-outputs: [stderr]
# Force to create a new one member cluster.
force-new-cluster: false
auto-compaction-mode: periodic
auto-compaction-retention: "1"
```
subnet enviroment setup
```shell
etcdctl \
--cert-file /etc/kubernetes/cert/server.pem \
--key-file /etc/kubernetes/cert/server-key.pem \
--ca-file /etc/kubernetes/cert/ca.pem \
--endpoints https://192.168.1.5:2379 mk /coreos.com/network/config '{ "Network": "10.1.0.0/16", "Backend": {"Type": "vxlan"} }'
```
check cluster health
~~~shell
etcdctl \
--cert-file /etc/kubernetes/cert/server.pem \
--key-file /etc/kubernetes/cert/server-key.pem \
--ca-file /etc/kubernetes/cert/ca.pem \
--endpoints https://192.168.1.5:2379 cluster-health
~~~
## 4. systemctl flannel.service
```shell
[Unit]
Description=flannel Server
Documentation=https://github.com/coreos/flannel
After=network.target etcd.service
Before=docker.service
[Service]
Type=simple
ExecStart=/usr/bin/flanneld -etcd-cafile=/etc/kubernetes/cert/ca.pem \
-etcd-certfile=/etc/kubernetes/cert/server.pem \
-etcd-endpoints=https://192.168.1.0:2379,https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 \
-etcd-keyfile=/etc/kubernetes/cert/server-key.pem \
-ip-masq=true -iface=192.168.1.0 -kube-api-url=https://192.168.1.0:6443 -kubeconfig-file=/etc/kubernetes/bootstrap.kubeconfig
Restart=on-failure
[Install]
WantedBy=multi-user.target
```
## 5. kubernetes cluster config
/root/.kube/config
```yaml
apiVersion: v1
clusters:
- cluster:
certificate-authority: /etc/kubernetes/cert/ca.pem
server: https://192.168.1.0:6443
name: local
contexts:
- context:
cluster: local
user: kubelet
name: kubelet-context
current-context: kubelet-context
kind: Config
preferences: {}
users:
- name: kubelet
user:
client-certificate: /etc/kubernetes/cert/server.pem
client-key: /etc/kubernetes/cert/server-key.pem
```
kubectl config use-context kubelet-context
## 6. systemctl docker.service
```shell
add parameter "--bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}"
```
```shell
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service flanneld.service
Wants=network-online.target
[Service]
EnvironmentFile=-/run/flannel/subnet.env
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
```
## 7. systemctl kube-apiserver.service
```shell
# more /usr/lib/systemd/system/kube-apiserver.service
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/kubernetes/kubernetes
After=etcd.service docker.service
Wants=etcd.service docker.service
Requires=etcd.service
[Service]
ExecStart=/usr/bin/kube-apiserver --storage-backend=etcd3 \
--etcd-servers=https://192.168.1.0:2379,https://192.168.1.1:2379,https://192.168.1.2:2379,https://192.168.1.3:2379 \
--etcd-cafile=/etc/kubernetes/cert/ca.pem \
--etcd-certfile=/etc/kubernetes/cert/server.pem \
--etcd-keyfile=/etc/kubernetes/cert/server-key.pem \
--tls-cert-file=/etc/kubernetes/cert/server.pem \
--tls-private-key-file=/etc/kubernetes/cert/server-key.pem \
--client-ca-file=/etc/kubernetes/cert/ca.pem \
--service-account-key-file=/etc/kubernetes/cert/server-key.pem \
--insecure-bind-address=0.0.0.0 --insecure-port=8080 \
--service-cluster-ip-range=10.2.0.0/24 --service-node-port-range=3-65535 \
--admission-control=NamespaceLifecycle,SecurityContextDeny,ServiceAccount,DefaultStorageClass,ResourceQuota \
#--admission-control= \
--logtostderr=true --log-dir=/var/log/kubernetes --v=2
Restart=on-failure
Type=notify
[Install]
WantedBy=multi-user.target
```
## 8. systemctl kube-scheduler.service
```shell
# more /usr/lib/systemd/system/kube-scheduler.service
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=kube-apiserver.service
Requires=kube-apiserver.service
[Service]
ExecStart=/usr/bin/kube-scheduler --master=http://192.168.1.0:8080 \
--logtostderr=true --log-dir=/var/log/kubernetes --v=2
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
```
## 9. systemctl kube-controller-manager.service
```shell
# more /usr/lib/systemd/system/kube-controller-manager.service
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=kube-apiserver.service
Requires=kube-apiserver.service
[Service]
ExecStart=/usr/bin/kube-controller-manager \
--tls-cert-file=/etc/kubernetes/cert/server.pem \
--tls-private-key-file=/etc/kubernetes/cert/server-key.pem \
--root-ca-file=/etc/kubernetes/cert/ca.pem \
--service-account-private-key-file=/etc/kubernetes/cert/server-key.pem \
--master=http://192.168.1.0:8080 \
--logtostderr=true --log-dir=/var/log/kubernetes --v=2
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
```
## 10.systemctl kubelet.service
zoo0
```shell
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/bin/kubelet --address=0.0.0.0 --port=10250 --hostname-override=192.168.1.0 \
--allow-privileged=false --kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
--cluster-dns=10.2.0.2 --cluster-domain=cluster.local --fail-swap-on=false \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 --cgroup-driver=cgroupfs
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
```
zoo1
```shell
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/bin/kubelet --address=0.0.0.0 --port=10250 --hostname-override=192.168.1.1 \
--allow-privileged=false --kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
--cluster-dns=10.2.0.2 --cluster-domain=cluster.local --fail-swap-on=false \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 --cgroup-driver=cgroupfs
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
```
zoo2
```shell
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/bin/kubelet --address=0.0.0.0 --port=10250 --hostname-override=192.168.1.2 \
--allow-privileged=false --kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
--cluster-dns=10.2.0.2 --cluster-domain=cluster.local --fail-swap-on=false \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 --cgroup-driver=cgroupfs
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
```
zoo3
```shell
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/bin/kubelet --address=0.0.0.0 --port=10250 --hostname-override=192.168.1.3 \
--allow-privileged=false --kubeconfig=/etc/kubernetes/bootstrap.kubeconfig \
--cluster-dns=10.2.0.2 --cluster-domain=cluster.local --fail-swap-on=false \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 --cgroup-driver=cgroupfs
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target
```
## 11.systemctl Kube-proxy.service
zoo0
```shell
[Unit]
Description=Kubernetes Kube-proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=kubelet.service
Requires=kubelet.service
[Service]
ExecStart=/usr/bin/kube-proxy \
--bind-address=0.0.0.0 --hostname-override=192.168.1.0 \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 \
--kubeconfig=/etc/kubernetes/bootstrap.kubeconfig
Restart=on-failure
LimitNOFILE=65536
KillMode=process
[Install]
WantedBy=multi-user.target
```
zoo1
```shell
[Unit]
Description=Kubernetes Kube-proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=kubelet.service
Requires=kubelet.service
[Service]
ExecStart=/usr/bin/kube-proxy \
--bind-address=0.0.0.0 --hostname-override=192.168.1.1 \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 \
--kubeconfig=/etc/kubernetes/bootstrap.kubeconfig
Restart=on-failure
LimitNOFILE=65536
KillMode=process
[Install]
WantedBy=multi-user.target
```
zoo2
```shell
[Unit]
Description=Kubernetes Kube-proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=kubelet.service
Requires=kubelet.service
[Service]
ExecStart=/usr/bin/kube-proxy \
--bind-address=0.0.0.0 --hostname-override=192.168.1.2 \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 \
--kubeconfig=/etc/kubernetes/bootstrap.kubeconfig
Restart=on-failure
LimitNOFILE=65536
KillMode=process
[Install]
WantedBy=multi-user.target
```
zoo3
```shell
[Unit]
Description=Kubernetes Kube-proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=kubelet.service
Requires=kubelet.service
[Service]
ExecStart=/usr/bin/kube-proxy \
--bind-address=0.0.0.0 --hostname-override=192.168.1.3 \
--logtostderr=true --log-dir=/var/log/kubernetes --v=4 \
--kubeconfig=/etc/kubernetes/bootstrap.kubeconfig
Restart=on-failure
LimitNOFILE=65536
KillMode=process
[Install]
WantedBy=multi-user.target
```
## 12. start service
1. start etcd.service
2. start flannel.service
3. check etcd cluster health
```shell
etcdctl \
--cert-file /etc/kubernetes/cert/etcd.pem \
--key-file /etc/kubernetes/cert/etcd-key.pem \
--ca-file /etc/kubernetes/cert/etcd-root-ca.pem \
--endpoints https://192.168.1.0:2379 cluster-health
```
```shell
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
systemctl start kubelet.service
systemctl start kube-proxy.service
kubectl get nodes
kubectl get svc
```
## 13. deploy kubernetes-dashboard
```shell
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml
```
## 14. deploy core-dns
```yaml
#CHINE_GENERATED_WARNING__
apiVersion: v1
kind: ServiceAccount
metadata:
name: coredns
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
kubernetes.io/bootstrapping: rbac-defaults
addonmanager.kubernetes.io/mode: Reconcile
name: system:coredns
rules:
- apiGroups:
- ""
resources:
- endpoints
- services
- pods
- namespaces
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
addonmanager.kubernetes.io/mode: EnsureExists
name: system:coredns
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:coredns
subjects:
- kind: ServiceAccount
name: coredns
namespace: kube-system
---
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
labels:
addonmanager.kubernetes.io/mode: EnsureExists
data:
Corefile: |
.:53 {
errors
health
kubernetes default.svc.default.svc.cluster.local cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
proxy . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: coredns
namespace: kube-system
labels:
k8s-app: coredns
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/name: "CoreDNS"
spec:
# replicas: not specified here:
# 1. In order to make Addon Manager do not reconcile this replicas parameter.
# 2. Default is 1.
# 3. Will be tuned in real time if DNS horizontal auto-scaling is turned on.
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
selector:
matchLabels:
k8s-app: coredns
template:
metadata:
labels:
k8s-app: coredns
annotations:
seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
spec:
serviceAccountName: coredns
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
containers:
- name: coredns
image: coredns/coredns:1.2.6
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 170Mi
requests:
cpu: 100m
memory: 70Mi
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
readOnly: true
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 9153
name: metrics
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_BIND_SERVICE
drop:
- all
readOnlyRootFilesystem: true
dnsPolicy: Default
volumes:
- name: config-volume
configMap:
name: coredns
items:
- key: Corefile
path: Corefile
---
apiVersion: v1
kind: Service
metadata:
name: kube-dns
namespace: kube-system
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
labels:
k8s-app: coredns
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/name: "CoreDNS"
spec:
selector:
k8s-app: coredns
clusterIP: 10.2.0.2
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
protocol: TCP
```
## 15. check dns
```shell
[root@localhost kubernetes]# kubectl exec busybox1 nslookup kubernetes
Server: 10.2.0.2
Address 1: 10.2.0.2 kube-dns.kube-system.svc.default.svc.default.svc.cluster.local
Name: kubernetes
Address 1: 10.1.0.1 kubernetes.default.svc.default.svc.default.svc.cluster.local
```