镜像离线打包脚本

    1. docker pull rancher/coreos-etcd:v3.4.3-rancher1
    2. docker pull rancher/rke-tools:v0.1.59
    3. docker pull rancher/k8s-dns-kube-dns:1.15.2
    4. docker pull rancher/k8s-dns-dnsmasq-nanny:1.15.2
    5. docker pull rancher/k8s-dns-sidecar:1.15.2
    6. docker pull rancher/cluster-proportional-autoscaler:1.7.1
    7. docker pull rancher/coredns-coredns:1.6.9
    8. docker pull rancher/k8s-dns-node-cache:1.15.7
    9. docker pull rancher/hyperkube:v1.18.6-rancher1
    10. docker pull rancher/coreos-flannel:v0.12.0
    11. docker pull rancher/flannel-cni:v0.3.0-rancher6
    12. docker pull rancher/calico-node:v3.13.4
    13. docker pull rancher/calico-cni:v3.13.4
    14. docker pull rancher/calico-kube-controllers:v3.13.4
    15. docker pull rancher/calico-ctl:v3.13.4
    16. docker pull rancher/calico-pod2daemon-flexvol:v3.13.4
    17. docker pull weaveworks/weave-kube:2.6.4
    18. docker pull weaveworks/weave-npc:2.6.4
    19. docker pull rancher/pause:3.1
    20. docker pull rancher/nginx-ingress-controller:nginx-0.32.0-rancher1
    21. docker pull rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1
    22. docker pull rancher/metrics-server:v0.3.6
    1. [root@uat-rancher-node01 rancher]# ll *.tar
    2. -rw-rw-r-- 1 root root 226441216 Aug 29 20:53 calico-cni.tar
    3. -rw-rw-r-- 1 root root 48206848 Aug 29 20:51 calico-ctl.tar
    4. -rw-rw-r-- 1 root root 56617984 Aug 29 20:50 calico-kube-controllers.tar
    5. -rw-rw-r-- 1 root root 265684992 Aug 29 20:55 calico-node.tar
    6. -rw-rw-r-- 1 root root 114141696 Aug 29 20:54 calico-pod2daemon-flexvol.tar
    7. -rw-rw-r-- 1 root root 41323520 Aug 29 20:42 cluster-proportional-autoscaler.tar
    8. -rw-rw-r-- 1 root root 43297792 Aug 29 20:47 coredns-coredns.tar
    9. -rw-rw-r-- 1 root root 85169664 Aug 29 20:46 coreos-etcd.tar
    10. -rw-rw-r-- 1 root root 1552846336 Aug 29 20:59 hyperkube.tar
    11. -rw-rw-r-- 1 root root 40140288 Aug 29 20:34 k8s-dns-dnsmasq-nanny.tar
    12. -rw-rw-r-- 1 root root 88547328 Aug 29 20:38 k8s-dns-kube-dns.tar
    13. -rw-rw-r-- 1 root root 92754944 Aug 29 20:43 k8s-dns-node-cache.tar
    14. -rw-rw-r-- 1 root root 80885760 Aug 29 20:39 k8s-dns-sidecar.tar
    15. -rw-rw-r-- 1 root root 41199616 Aug 29 20:44 metrics-server.tar
    16. -rw-rw-r-- 1 root root 5144064 Aug 29 20:34 nginx-ingress-controller-defaultbackend.tar
    17. -rw-rw-r-- 1 root root 331629056 Aug 29 20:48 nginx-ingress-controller.tar
    18. -rw-rw-r-- 1 root root 754176 Aug 29 20:34 pause.tar
    19. -rw-rw-r-- 1 root root 135227392 Aug 29 20:56 rke-tools.tar
    1. [root@uat-rancher-node01 rancher]# ll *.tar|awk '{print $NF}'
    2. calico-cni.tar
    3. calico-ctl.tar
    4. calico-kube-controllers.tar
    5. calico-node.tar
    6. calico-pod2daemon-flexvol.tar
    7. cluster-proportional-autoscaler.tar
    8. coredns-coredns.tar
    9. coreos-etcd.tar
    10. hyperkube.tar
    11. k8s-dns-dnsmasq-nanny.tar
    12. k8s-dns-kube-dns.tar
    13. k8s-dns-node-cache.tar
    14. k8s-dns-sidecar.tar
    15. metrics-server.tar
    16. nginx-ingress-controller-defaultbackend.tar
    17. nginx-ingress-controller.tar
    18. pause.tar
    19. rke-tools.tar
    20. [root@uat-rancher-node01 rancher]#
    21. [root@uat-rancher-node01 rancher]# ll *.tar|awk '{print $NF}'|sed -r 's#(.*)#docker load -i \1#' |bash
    22. b76aa58f4c23: Loading layer [==================================================>] 107.4MB/107.4MB
    23. 566d20c1ccdf: Loading layer [==================================================>] 20.48kB/20.48kB
    24. f3e35332f964: Loading layer [==================================================>] 101.2MB/101.2MB
    25. 109a0c66209a: Loading layer [==================================================>] 10.24kB/10.24kB
    26. 6ac59be9ed64: Loading layer [==================================================>] 2.56kB/2.56kB
    27. 3b481276ac88: Loading layer [==================================================>] 17.79MB/17.79MB
    28. 11703ffeceb1: Loading layer [==================================================>] 13.82kB/13.82kB
    29. Loaded image: rancher/calico-cni:v3.13.4
    30. 1b3ee35aacca: Loading layer [==================================================>] 5.84MB/5.84MB
    31. 419eaad88244: Loading layer [==================================================>] 42.35MB/42.35MB
    32. Loaded image: rancher/calico-ctl:v3.13.4
    33. 7bd4affc29eb: Loading layer [==================================================>] 13.82kB/13.82kB
    34. 523c4550fd32: Loading layer [==================================================>] 53.52MB/53.52MB
    35. b5dadf89acf5: Loading layer [==================================================>] 3.07MB/3.07MB
    36. Loaded image: rancher/calico-kube-controllers:v3.13.4
    37. f80c95f61fff: Loading layer [==================================================>] 108.5MB/108.5MB
    38. eddba477a8ae: Loading layer [==================================================>] 20.48kB/20.48kB
    39. 76224ad063b6: Loading layer [==================================================>] 2.781MB/2.781MB
    40. 2ca638bbce84: Loading layer [==================================================>] 3.298MB/3.298MB
    41. 62b8adc82952: Loading layer [==================================================>] 3.072kB/3.072kB
    42. 2e1e28e9c135: Loading layer [==================================================>] 75.24MB/75.24MB
    43. 1fa8cad5d0e3: Loading layer [==================================================>] 4.096kB/4.096kB
    44. af19fd058de9: Loading layer [==================================================>] 7.185MB/7.185MB
    45. 4ba854688443: Loading layer [==================================================>] 6.052MB/6.052MB
    46. db5b88cbf87f: Loading layer [==================================================>] 2.048kB/2.048kB
    47. 9fcde00c5e9a: Loading layer [==================================================>] 13.82kB/13.82kB
    48. 5f956aaa317c: Loading layer [==================================================>] 61.32MB/61.32MB
    49. 151cbe937db5: Loading layer [==================================================>] 1.251MB/1.251MB
    50. Loaded image: rancher/calico-node:v3.13.4
    51. 724362325411: Loading layer [==================================================>] 2.048kB/2.048kB
    52. 689becca0610: Loading layer [==================================================>] 13.82kB/13.82kB
    53. 1140aa2f2fa9: Loading layer [==================================================>] 5.12kB/5.12kB
    54. 6c83a0e86620: Loading layer [==================================================>] 5.606MB/5.606MB
    55. Loaded image: rancher/calico-pod2daemon-flexvol:v3.13.4
    56. 932da5156413: Loading layer [==================================================>] 3.062MB/3.062MB
    57. 7b00adda7217: Loading layer [==================================================>] 38.25MB/38.25MB
    58. Loaded image: rancher/cluster-proportional-autoscaler:1.7.1
    59. 225df95e717c: Loading layer [==================================================>] 336.4kB/336.4kB
    60. 8762ba1e4767: Loading layer [==================================================>] 42.95MB/42.95MB
    61. Loaded image: rancher/coredns-coredns:1.6.9
    62. fe9a8b4f1dcc: Loading layer [==================================================>] 43.87MB/43.87MB
    63. 816dcf8208f7: Loading layer [==================================================>] 23.72MB/23.72MB
    64. 4da29af72f7f: Loading layer [==================================================>] 17.55MB/17.55MB
    65. e94602b7c460: Loading layer [==================================================>] 2.56kB/2.56kB
    66. e74140cc410f: Loading layer [==================================================>] 3.072kB/3.072kB
    67. 0c356e885c8a: Loading layer [==================================================>] 3.072kB/3.072kB
    68. Loaded image: rancher/coreos-etcd:v3.4.3-rancher1
    69. 82a5cde9d9a9: Loading layer [==================================================>] 53.87MB/53.87MB
    70. a2b38eae1b39: Loading layer [==================================================>] 21.62MB/21.62MB
    71. f378e9487360: Loading layer [==================================================>] 5.168MB/5.168MB
    72. a35a0b8b55f5: Loading layer [==================================================>] 4.608kB/4.608kB
    73. dea351e760ec: Loading layer [==================================================>] 8.192kB/8.192kB
    74. d57a645c2b0c: Loading layer [==================================================>] 8.704kB/8.704kB
    75. 80c8b272a31c: Loading layer [==================================================>] 9.728kB/9.728kB
    76. 588868021aa0: Loading layer [==================================================>] 1.824MB/1.824MB
    77. 0a514e5f8343: Loading layer [==================================================>] 5.12kB/5.12kB
    78. e46a9dd0cf8f: Loading layer [==================================================>] 23.04kB/23.04kB
    79. ea3e975f63d4: Loading layer [==================================================>] 349.1MB/349.1MB
    80. 488428ef6ca2: Loading layer [==================================================>] 72.17MB/72.17MB
    81. 8cff9f524c8b: Loading layer [==================================================>] 469.4MB/469.4MB
    82. 9105b0079c7f: Loading layer [==================================================>] 3.584kB/3.584kB
    83. 03a3faf297ee: Loading layer [==================================================>] 579.6MB/579.6MB
    84. Loaded image: rancher/hyperkube:v1.18.6-rancher1
    85. d9ff549177a9: Loading layer [==================================================>] 4.671MB/4.671MB
    86. 257e31c9cb28: Loading layer [==================================================>] 2.56kB/2.56kB
    87. e3418a4c0703: Loading layer [==================================================>] 362kB/362kB
    88. 39fe80c5a89b: Loading layer [==================================================>] 3.584kB/3.584kB
    89. 295a83faf517: Loading layer [==================================================>] 35.08MB/35.08MB
    90. Loaded image: rancher/k8s-dns-dnsmasq-nanny:1.15.2
    91. 47d8bc5560bb: Loading layer [==================================================>] 44.66MB/44.66MB
    92. Loaded image: rancher/k8s-dns-kube-dns:1.15.2
    93. 35c35a973795: Loading layer [==================================================>] 2.276MB/2.276MB
    94. d71bb3de1e76: Loading layer [==================================================>] 46.59MB/46.59MB
    95. Loaded image: rancher/k8s-dns-node-cache:1.15.7
    96. e3b0318787d0: Loading layer [==================================================>] 37MB/37MB
    97. Loaded image: rancher/k8s-dns-sidecar:1.15.2
    98. 7bf3709d22bb: Loading layer [==================================================>] 38.13MB/38.13MB
    99. Loaded image: rancher/metrics-server:v0.3.6
    100. b108d4968233: Loading layer [==================================================>] 5.134MB/5.134MB
    101. Loaded image: rancher/nginx-ingress-controller-defaultbackend:1.5-rancher1
    102. beee9f30bc1f: Loading layer [==================================================>] 5.862MB/5.862MB
    103. 378129e7fefc: Loading layer [==================================================>] 161.4MB/161.4MB
    104. 2c4876c55341: Loading layer [==================================================>] 6.144kB/6.144kB
    105. a5cd644ea51c: Loading layer [==================================================>] 30.43MB/30.43MB
    106. f99824ffc859: Loading layer [==================================================>] 16.91MB/16.91MB
    107. e816d879e6f5: Loading layer [==================================================>] 4.096kB/4.096kB
    108. d43abedb29d5: Loading layer [==================================================>] 8.042MB/8.042MB
    109. bfa0001530d1: Loading layer [==================================================>] 50.41MB/50.41MB
    110. 4becb331f71a: Loading layer [==================================================>] 6.656kB/6.656kB
    111. b2a014433f54: Loading layer [==================================================>] 37.57MB/37.57MB
    112. 7863f1fb0c1e: Loading layer [==================================================>] 20.9MB/20.9MB
    113. 909651a2178f: Loading layer [==================================================>] 6.656kB/6.656kB
    114. Loaded image: rancher/nginx-ingress-controller:nginx-0.32.0-rancher1
    115. e17133b79956: Loading layer [==================================================>] 744.4kB/744.4kB
    116. Loaded image: rancher/pause:3.1
    117. f1b5933fe4b5: Loading layer [==================================================>] 5.796MB/5.796MB
    118. 2bdf88b2699d: Loading layer [==================================================>] 17.72MB/17.72MB
    119. 519b820c8bb3: Loading layer [==================================================>] 1.603MB/1.603MB
    120. eed905e10fc1: Loading layer [==================================================>] 24.45MB/24.45MB
    121. 126480a1531c: Loading layer [==================================================>] 3.072kB/3.072kB
    122. 021ed1072f21: Loading layer [==================================================>] 56.38MB/56.38MB
    123. 25f3c3b9821e: Loading layer [==================================================>] 3.509MB/3.509MB
    124. b5449afc16e1: Loading layer [==================================================>] 16.08MB/16.08MB
    125. 8122015cea19: Loading layer [==================================================>] 4.096kB/4.096kB
    126. 06002c2e3403: Loading layer [==================================================>] 4.096kB/4.096kB
    127. 3f81d91d9bbb: Loading layer [==================================================>] 5.632kB/5.632kB
    128. c6382345d3ee: Loading layer [==================================================>] 12.8kB/12.8kB
    129. 4ab3470e2725: Loading layer [==================================================>] 9.601MB/9.601MB
    130. Loaded image: rancher/rke-tools:v0.1.59
    131. [root@uat-rancher-node01 rancher]# docker image ls
    132. REPOSITORY TAG IMAGE ID CREATED SIZE
    133. rancher/hyperkube v1.18.6-rancher1 5a1e9f24e782 6 weeks ago 1.51GB
    134. rancher/rke-tools v0.1.59 904d2afa34c8 7 weeks ago 132MB
    135. rancher/calico-node v3.13.4 c91d49e6f044 3 months ago 261MB
    136. rancher/calico-pod2daemon-flexvol v3.13.4 c5dca18c0346 3 months ago 112MB
    137. rancher/calico-cni v3.13.4 9e1176a74e85 3 months ago 225MB
    138. rancher/calico-ctl v3.13.4 cbd105686d60 3 months ago 47.9MB
    139. rancher/calico-kube-controllers v3.13.4 f9f70a2e922f 3 months ago 56.6MB
    140. rancher/nginx-ingress-controller nginx-0.32.0-rancher1 eda78cfd6f9d 3 months ago 328MB
    141. rancher/coredns-coredns 1.6.9 4e797b323460 5 months ago 43.2MB
    142. rancher/coreos-etcd v3.4.3-rancher1 a0b920cf970d 10 months ago 83.6MB
    143. rancher/metrics-server v0.3.6 9dd718864ce6 10 months ago 39.9MB
    144. rancher/k8s-dns-node-cache 1.15.7 ce4f91502e1b 10 months ago 91MB
    145. rancher/cluster-proportional-autoscaler 1.7.1 14afc47fd5af 12 months ago 40.1MB
    146. rancher/k8s-dns-sidecar 1.15.2 ffc7ccc8fded 16 months ago 79.3MB
    147. rancher/k8s-dns-kube-dns 1.15.2 4ad5e24b1ad2 16 months ago 87MB
    148. rancher/k8s-dns-dnsmasq-nanny 1.15.2 c4d9bb9e5ff0 16 months ago 39.8MB
    149. rancher/nginx-ingress-controller-defaultbackend 1.5-rancher1 b5af743e5984 23 months ago 5.13MB
    150. rancher/pause 3.1 da86e6ba6ca1 2 years ago 742kB
    151. [root@uat-rancher-node01 rancher]#

    批量下载镜像并打包推送到harbor镜像仓库

    1. [root@salt-master ~]# docker push 10.182.220.240:80/rancher/calico-pod2daemon-flexvol:v3.13.4
    2. The push refers to a repository [10.182.220.240:80/rancher/calico-pod2daemon-flexvol]
    3. 6c83a0e86620: Pushed
    4. 1140aa2f2fa9: Pushed
    5. 689becca0610: Pushed
    6. 724362325411: Pushed
    7. eddba477a8ae: Mounted from rancher/calico-node
    8. f80c95f61fff: Mounted from rancher/calico-node
    9. v3.13.4: digest: sha256:3a12c023e964104ebf8af330bc74fa25831e961c871f8024bd6917c1357a57a6 size: 1571
    10. [root@salt-master ~]#

    image.png

    Harbor私有镜像仓库部署
    [root@harbor harbor]# vim harbor.yml
    image.png

    harbor证书配置

    1. [root@harbor harbor]# cat key.sh
    2. #!/bin/bash
    3. # 在该目录下操作生成证书,正好供harbor.yml使用
    4. #mkdir -p /data/cert
    5. cd /app/docker-compose/harbor/key
    6. openssl genrsa -out ca.key 4096
    7. openssl req -x509 -new -nodes -sha512 -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=www.harbor.mobi" -key ca.key -out ca.crt
    8. openssl genrsa -out www.harbor.mobi.key 4096
    9. openssl req -sha512 -new -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=www.harbor.mobi" -key www.harbor.mobi.key -out www.harbor.mobi.csr
    10. cat > v3.ext <<-EOF
    11. authorityKeyIdentifier=keyid,issuer
    12. basicConstraints=CA:FALSE
    13. keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
    14. extendedKeyUsage = serverAuth
    15. subjectAltName = @alt_names
    16. [alt_names]
    17. DNS.1=www.harbor.mobi
    18. DNS.2=harbor
    19. DNS.3=ks-allinone
    20. EOF
    21. openssl x509 -req -sha512 -days 3650 -extfile v3.ext -CA ca.crt -CAkey ca.key -CAcreateserial -in www.harbor.mobi.csr -out www.harbor.mobi.crt
    22. openssl x509 -inform PEM -in www.harbor.mobi.crt -out www.harbor.mobi.cert
    23. cp www.harbor.mobi.crt /etc/pki/ca-trust/source/anchors/www.harbor.mobi.crt
    24. update-ca-trust
    25. [root@harbor harbor]#
    1. [root@harbor harbor]# tree /app/docker-compose/harbor/key/
    2. /app/docker-compose/harbor/key/
    3. ├── ca.crt
    4. ├── ca.key
    5. ├── ca.srl
    6. ├── v3.ext
    7. ├── www.harbor.mobi.cert
    8. ├── www.harbor.mobi.crt
    9. ├── www.harbor.mobi.csr
    10. └── www.harbor.mobi.key
    11. 0 directories, 8 files
    12. [root@harbor harbor]#

    新建一个目录
    www.harbor.mobi
    复制到各个dockers节点的www.harbor.mobi

    1. [rancher@uat-rancher-node01 ~]$ tree /etc/docker/certs.d/www.harbor.mobi/
    2. /etc/docker/certs.d/www.harbor.mobi/
    3. ├── ca.crt
    4. ├── www.harbor.mobi.cert
    5. └── www.harbor.mobi.key
    6. 0 directories, 3 files
    7. [rancher@uat-rancher-node01 ~]$

    image.png

    //“registry-mirrors”: [“https://10.182.220.240“],
    “insecure-registries”: [“https://10.182.220.240“],

    1. [root@uat-rancher-node04 ~]# docker login https://10.182.220.240
    2. Username: liwm
    3. Password:
    4. WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    5. Configure a credential helper to remove this warning. See
    6. https://docs.docker.com/engine/reference/commandline/login/#credentials-store
    7. Login Succeeded
    8. [root@uat-rancher-node04 ~]# docker login 10.182.220.242
    9. Username: admin
    10. Password:
    11. WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
    12. Configure a credential helper to remove this warning. See
    13. https://docs.docker.com/engine/reference/commandline/login/#credentials-store
    14. Login Succeeded
    15. [root@uat-rancher-node04 ~]# cat /etc/docker/daemon.json
    16. {
    17. "graph": "/app/docker",
    18. "max-concurrent-downloads": 3,
    19. "max-concurrent-uploads": 5,
    20. "insecure-registries": ["https://10.182.220.240","http://10.182.220.242"],
    21. "storage-driver": "overlay2",
    22. "storage-opts": ["overlay2.override_kernel_check=true"],
    23. "log-driver": "json-file",
    24. "log-opts": {"max-size": "100m","max-file": "3"}
    25. }
    26. [root@uat-rancher-node04 ~]#

    image.png
    配置多个私有仓库

    1. [rancher@uat-rancher-node01 ~]$ cat /etc/docker/daemon.json
    2. {
    3. "graph": "/app/docker",
    4. "max-concurrent-downloads": 3,
    5. "max-concurrent-uploads": 5,
    6. "insecure-registries": ["https://10.182.220.240"],
    7. "storage-driver": "overlay2",
    8. "storage-opts": ["overlay2.override_kernel_check=true"],
    9. "log-driver": "json-file",
    10. "log-opts": {"max-size": "100m","max-file": "3"}
    11. }
    12. [rancher@uat-rancher-node01 ~]$

    image.png
    image.png
    image.png

    rke部署kubernetes集群
    ##配置私有仓库地址(需要配置证书)

    修改rke cluster.yml部署配置文件

    1. [rancher@uat-rancher-node01 ~]$ cat cluster.yml
    2. nodes:
    3. - address: 10.182.220.241
    4. hostname_override: uat-rancher-node01
    5. internal_address:
    6. user: rancher
    7. role: [controlplane,etcd]
    8. - address: 10.182.220.242
    9. hostname_override: uat-rancher-node02
    10. internal_address:
    11. user: rancher
    12. role: [controlplane,etcd]
    13. - address: 10.182.220.243
    14. hostname_override: uat-rancher-node03
    15. internal_address:
    16. user: rancher
    17. role: [controlplane,etcd]
    18. - address: 10.182.220.244
    19. hostname_override: uat-rancher-node04
    20. internal_address:
    21. user: rancher
    22. role: [worker]
    23. - address: 10.182.220.245
    24. hostname_override: uat-rancher-node05
    25. internal_address:
    26. user: rancher
    27. role: [worker]
    28. # 定义kubernetes版本
    29. kubernetes_version: v1.18.6-rancher1-2
    30. # 如果要使用私有仓库中的镜像,配置以下参数来指定默认私有仓库地址需要启用证书。
    31. private_registries:
    32. - url: 10.182.220.240
    33. user: liwm
    34. password: !Q2w3e4r
    35. is_default: true
    36. services:
    37. etcd:
    38. # 扩展参数
    39. extra_args:
    40. # 240个小时后自动清理磁盘碎片,通过auto-compaction-retention对历史数据压缩后,后端数据库可能会出现内部碎片。内部碎片是指空闲状态的,能被后端使用但是仍然消耗存储空间,碎片整理过程将此存储空间释放回文>件系统
    41. auto-compaction-retention: 240 #(单位小时)
    42. # 修改空间配额为6442450944,默认2G,最大8G
    43. quota-backend-bytes: '6442450944'
    44. # 自动备份
    45. snapshot: true
    46. creation: 5m0s
    47. retention: 24h
    48. kubelet:
    49. extra_args:
    50. # 支持静态Pod。在主机/etc/kubernetes/目录下创建manifest目录,Pod YAML文件放在/etc/kubernetes/manifest/目录下
    51. pod-manifest-path: "/etc/kubernetes/manifest/"
    52. # 有几个网络插件可以选择:flannel、canal、calico,Rancher2默认canal
    53. network:
    54. plugin: canal
    55. options:
    56. flannel_backend_type: "vxlan"
    57. # 可以设置provider: none来禁用ingress controller
    58. ingress:
    59. provider: nginx
    60. node_selector:
    61. app: ingress
    62. [rancher@uat-rancher-node01 ~]$

    image.png

    helm 部署 rancher

    helm证书配置

    1. [rancher@uat-rancher-node01 ~]$ cat helm.sh
    2. #!/bin/bash -e
    3. # * 为必改项
    4. # * 服务器FQDN或颁发者名(更换为你自己的域名)
    5. CN='rancher'
    6. # 扩展信任IP或域名
    7. ## 一般ssl证书只信任域名的访问请求,有时候需要使用ip去访问server,那么需要给ssl证书添加扩展IP,用逗号隔开。配置节点ip和lb的ip。
    8. SSL_IP='10.182.220.241,10.182.220.242,10.182.220.243,10.182.220.244,10.182.220.245,10.182.220.246'
    9. SSL_DNS=''
    10. # 国家名(2个字母的代号)
    11. C=CN
    12. # 证书加密位数
    13. SSL_SIZE=2048
    14. # 证书有效期
    15. DATE=${DATE:-3650}
    16. # 配置文件
    17. SSL_CONFIG='openssl.cnf'
    18. if [[ -z $SILENT ]]; then
    19. echo "----------------------------"
    20. echo "| SSL Cert Generator |"
    21. echo "----------------------------"
    22. echo
    23. fi
    24. export CA_KEY=${CA_KEY-"cakey.pem"}
    25. export CA_CERT=${CA_CERT-"cacerts.pem"}
    26. export CA_SUBJECT=ca-$CN
    27. export CA_EXPIRE=${DATE}
    28. export SSL_CONFIG=${SSL_CONFIG}
    29. export SSL_KEY=$CN.key
    30. export SSL_CSR=$CN.csr
    31. export SSL_CERT=$CN.crt
    32. export SSL_EXPIRE=${DATE}
    33. export SSL_SUBJECT=${CN}
    34. export SSL_DNS=${SSL_DNS}
    35. export SSL_IP=${SSL_IP}
    36. export K8S_SECRET_COMBINE_CA=${K8S_SECRET_COMBINE_CA:-'true'}
    37. [[ -z $SILENT ]] && echo "--> Certificate Authority"
    38. if [[ -e ./${CA_KEY} ]]; then
    39. [[ -z $SILENT ]] && echo "====> Using existing CA Key ${CA_KEY}"
    40. else
    41. [[ -z $SILENT ]] && echo "====> Generating new CA key ${CA_KEY}"
    42. openssl genrsa -out ${CA_KEY} ${SSL_SIZE} > /dev/null
    43. fi
    44. if [[ -e ./${CA_CERT} ]]; then
    45. [[ -z $SILENT ]] && echo "====> Using existing CA Certificate ${CA_CERT}"
    46. else
    47. [[ -z $SILENT ]] && echo "====> Generating new CA Certificate ${CA_CERT}"
    48. openssl req -x509 -sha256 -new -nodes -key ${CA_KEY} -days ${CA_EXPIRE} -out ${CA_CERT} -subj "/CN=${CA_SUBJECT}" > /dev/null || exit 1
    49. fi
    50. echo "====> Generating new config file ${SSL_CONFIG}"
    51. cat > ${SSL_CONFIG} <<EOM
    52. [req]
    53. req_extensions = v3_req
    54. distinguished_name = req_distinguished_name
    55. [req_distinguished_name]
    56. [ v3_req ]
    57. basicConstraints = CA:FALSE
    58. keyUsage = nonRepudiation, digitalSignature, keyEncipherment
    59. extendedKeyUsage = clientAuth, serverAuth
    60. EOM
    61. if [[ -n ${SSL_DNS} || -n ${SSL_IP} ]]; then
    62. cat >> ${SSL_CONFIG} <<EOM
    63. subjectAltName = @alt_names
    64. [alt_names]
    65. EOM
    66. IFS=","
    67. dns=(${SSL_DNS})
    68. dns+=(${SSL_SUBJECT})
    69. for i in "${!dns[@]}"; do
    70. echo DNS.$((i+1)) = ${dns[$i]} >> ${SSL_CONFIG}
    71. done
    72. if [[ -n ${SSL_IP} ]]; then
    73. ip=(${SSL_IP})
    74. for i in "${!ip[@]}"; do
    75. echo IP.$((i+1)) = ${ip[$i]} >> ${SSL_CONFIG}
    76. done
    77. fi
    78. fi
    79. [[ -z $SILENT ]] && echo "====> Generating new SSL KEY ${SSL_KEY}"
    80. openssl genrsa -out ${SSL_KEY} ${SSL_SIZE} > /dev/null || exit 1
    81. [[ -z $SILENT ]] && echo "====> Generating new SSL CSR ${SSL_CSR}"
    82. openssl req -sha256 -new -key ${SSL_KEY} -out ${SSL_CSR} -subj "/CN=${SSL_SUBJECT}" -config ${SSL_CONFIG} > /dev/null || exit 1
    83. [[ -z $SILENT ]] && echo "====> Generating new SSL CERT ${SSL_CERT}"
    84. openssl x509 -sha256 -req -in ${SSL_CSR} -CA ${CA_CERT} -CAkey ${CA_KEY} -CAcreateserial -out ${SSL_CERT} \
    85. -days ${SSL_EXPIRE} -extensions v3_req -extfile ${SSL_CONFIG} > /dev/null || exit 1
    86. if [[ -z $SILENT ]]; then
    87. echo "====> Complete"
    88. echo "keys can be found in volume mapped to $(pwd)"
    89. echo
    90. echo "====> Output results as YAML"
    91. echo "---"
    92. echo "ca_key: |"
    93. cat $CA_KEY | sed 's/^/ /'
    94. echo
    95. echo "ca_cert: |"
    96. cat $CA_CERT | sed 's/^/ /'
    97. echo
    98. echo "ssl_key: |"
    99. cat $SSL_KEY | sed 's/^/ /'
    100. echo
    101. echo "ssl_csr: |"
    102. cat $SSL_CSR | sed 's/^/ /'
    103. echo
    104. echo "ssl_cert: |"
    105. cat $SSL_CERT | sed 's/^/ /'
    106. echo
    107. fi
    108. if [[ -n $K8S_SECRET_NAME ]]; then
    109. if [[ -n $K8S_SECRET_COMBINE_CA ]]; then
    110. [[ -z $SILENT ]] && echo "====> Adding CA to Cert file"
    111. cat ${CA_CERT} >> ${SSL_CERT}
    112. fi
    113. [[ -z $SILENT ]] && echo "====> Creating Kubernetes secret: $K8S_SECRET_NAME"
    114. kubectl delete secret $K8S_SECRET_NAME --ignore-not-found
    115. if [[ -n $K8S_SECRET_SEPARATE_CA ]]; then
    116. kubectl create secret generic \
    117. $K8S_SECRET_NAME \
    118. --from-file="tls.crt=${SSL_CERT}" \
    119. --from-file="tls.key=${SSL_KEY}" \
    120. --from-file="ca.crt=${CA_CERT}"
    121. else
    122. kubectl create secret tls \
    123. $K8S_SECRET_NAME \
    124. --cert=${SSL_CERT} \
    125. --key=${SSL_KEY}
    126. fi
    127. if [[ -n $K8S_SECRET_LABELS ]]; then
    128. [[ -z $SILENT ]] && echo "====> Labeling Kubernetes secret"
    129. IFS=$' \n\t' # We have to reset IFS or label secret will misbehave on some systems
    130. kubectl label secret \
    131. $K8S_SECRET_NAME \
    132. $K8S_SECRET_LABELS
    133. fi
    134. fi
    135. echo "4. 重命名服务证书"
    136. mv ${CN}.key tls.key
    137. mv ${CN}.crt tls.crt
    138. # 把生成的证书作为密文导入K8S
    139. ## * 指定K8S配置文件路径
    140. kubeconfig=/home/rancher/.kube/config
    141. kubectl --kubeconfig=$kubeconfig create namespace cattle-system
    142. kubectl --kubeconfig=$kubeconfig -n cattle-system create secret tls tls-rancher-ingress --cert=./tls.crt --key=./tls.key
    143. kubectl --kubeconfig=$kubeconfig -n cattle-system create secret generic tls-ca --from-file=cacerts.pem

    配置仓库地址
    image.png

    1. [rancher@uat-rancher-node01 rancher]$ cat values.yaml
    2. # Additional Trusted CAs.
    3. # Enable this flag and add your CA certs as a secret named tls-ca-additional in the namespace.
    4. # See README.md for details.
    5. additionalTrustedCAs: false
    6. antiAffinity: preferred
    7. # Audit Logs https://rancher.com/docs/rancher/v2.x/en/installation/api-auditing/
    8. # The audit log is piped to the console of the rancher-audit-log container in the rancher pod.
    9. # https://rancher.com/docs/rancher/v2.x/en/installation/api-auditing/
    10. # destination stream to sidecar container console or hostPath volume
    11. # level: Verbosity of logs, 0 to 3. 0 is off 3 is a lot.
    12. auditLog:
    13. destination: sidecar
    14. hostPath: /var/log/rancher/audit/
    15. level: 0
    16. maxAge: 1
    17. maxBackup: 1
    18. maxSize: 100
    19. fluentbitImage: 10.182.220.240/cnrancher/rancher-auditlog-fluentbit
    20. fluentbitImageTag: v1.0.0
    21. # The Mysql should be deployed manually and create the user and database schema for auditlog server.
    22. # You should use nonadministrative account and a high strength password to connect to the Mysql.
    23. auditLogServer:
    24. image: 10.182.220.240/cnrancher/rancher-auditlog-server
    25. imageTag: v1.0.0
    26. replicas: 1
    27. antiAffinity: preferred
    28. serverPort: 9000
    29. DBHost: localhost
    30. DBPort: 3306
    31. DBUser: root
    32. DBPassword: password
    33. DBName: rancher
    34. # Have Rancher detect and import the "local" Rancher server cluster
    35. # Adding the "local" cluster available in the GUI can be convenient, but any user with access to this cluster has "root" on any of the clusters that Rancher manages.
    36. # options; "auto", "false". (auto pretty much means true)
    37. addLocal: "auto"
    38. # Image for collecting rancher audit logs.
    39. # Important: update pkg/image/export/main.go when this default image is changed, so that it's reflected accordingly in rancher-images.txt generated for air-gapped setups.
    40. busyboxImage: 10.182.220.240/dev/busybox
    41. # Add debug flag to Rancher server
    42. debug: false
    43. # Extra environment variables passed to the rancher pods.
    44. # extraEnv:
    45. # - name: CATTLE_TLS_MIN_VERSION
    46. # value: "1.0"
    47. # Fully qualified name to reach your Rancher server
    48. # hostname: rancher.my.org
    49. ## Optional array of imagePullSecrets containing private registry credentials
    50. ## Ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
    51. imagePullSecrets: []
    52. # - name: secretName
    53. ### ingress ###
    54. # Readme for details and instruction on adding tls secrets.
    55. ingress:
    56. extraAnnotations:
    57. nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"
    58. nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
    59. nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
    60. # configurationSnippet - Add additional Nginx configuration. This example statically sets a header on the ingress.
    61. # configurationSnippet: |
    62. # more_set_input_headers "X-Forwarded-Host: {{ .Values.hostname }}";
    63. configurationSnippet: |
    64. more_clear_headers Server;
    65. tls:
    66. # options: rancher, letsEncrypt, secret
    67. source: rancher
    68. ### LetsEncrypt config ###
    69. # ProTip: The production environment only allows you to register a name 5 times a week.
    70. # Use staging until you have your config right.
    71. letsEncrypt:
    72. # email: none@example.com
    73. environment: production
    74. # If you are using certs signed by a private CA set to 'true' and set the 'tls-ca'
    75. # in the 'rancher-system' namespace. See the README.md for details
    76. privateCA: false
    77. # http[s] proxy server passed into rancher server.
    78. # proxy: http://<username>@<password>:<url>:<port>
    79. # comma separated list of domains or ip addresses that will not use the proxy
    80. noProxy: 127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
    81. # Override rancher image location for Air Gap installs
    82. rancherImage: 10.182.220.240/cnrancher/rancher
    83. ## set Air Gap registry for rancher
    84. # rancherRegistry: harbor.cnrancher.com
    85. systemDefaultRegistry: ""
    86. # rancher/rancher image tag. https://hub.docker.com/r/rancher/rancher/tags/
    87. # Defaults to .Chart.appVersion
    88. # rancherImageTag: v2.0.7
    89. # Override imagePullPolicy for rancher server images
    90. # options: Always, Never, IfNotPresent
    91. # Defaults to IfNotPresent
    92. # rancherImagePullPolicy: <pullPolicy>
    93. # Number of Rancher server replicas.
    94. replicas: 3
    95. # Set pod resource requests/limits for Rancher.
    96. resources: {}
    97. #
    98. # tls
    99. # Where to offload the TLS/SSL encryption
    100. # - ingress (default)
    101. # - external
    102. tls: ingress
    103. # Set to use the packaged system charts
    104. useBundledSystemChart: false
    105. service:
    106. type: ClusterIP
    107. ports:
    108. nodePort: 30443
    109. # Certmanager version compatibility
    110. certmanager:
    111. version: ""
    112. [rancher@uat-rancher-node01 rancher]$

    image.png

    1. helm install rancher rancher/ --namespace cattle-system --set rancherImage=cnrancher/rancher --set service.type=NodePort --set service.ports.nodePort=30001 --set tls=internal --set privateCA=true

    image.png

    image.png