Skip to content

Commit 60cd494

Browse files
authored
Merge pull request #21259 from gaoguangze111/bug-certificates-list-number
Correct list number
2 parents bf4f642 + 799faa2 commit 60cd494

File tree

1 file changed

+172
-85
lines changed

1 file changed

+172
-85
lines changed

content/zh/docs/concepts/cluster-administration/certificates.md

Lines changed: 172 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,15 @@ manually through `easyrsa`, `openssl` or `cfssl`.
3232

3333
<!--
3434
1. Download, unpack, and initialize the patched version of easyrsa3.
35-
-->
36-
37-
1. 下载、解压并初始化 easyrsa3 的补丁版本。
3835
3936
curl -LO https://storage.googleapis.com/kubernetes-release/easy-rsa/easy-rsa.tar.gz
4037
tar xzf easy-rsa.tar.gz
4138
cd easy-rsa-master/easyrsa3
4239
./easyrsa init-pki
43-
44-
<!--
45-
1. Generate a CA. (`--batch` set automatic mode. `--req-cn` default CN to use.)
46-
-->
47-
48-
1. 生成 CA(通过 `--batch` 参数设置自动模式。 通过 `--req-cn` 设置默认使用的 CN)
40+
1. Generate a new certificate authority (CA). `--batch` sets automatic mode;
41+
`--req-cn` specifies the Common Name (CN) for the CA's new root certificate.
4942
5043
./easyrsa --batch "--req-cn=${MASTER_IP}@`date +%s`" build-ca nopass
51-
52-
<!--
5344
1. Generate server certificate and key.
5445
The argument `--subject-alt-name` sets the possible IPs and DNS names the API server will
5546
be accessed with. The `MASTER_CLUSTER_IP` is usually the first IP from the service CIDR
@@ -58,8 +49,33 @@ manually through `easyrsa`, `openssl` or `cfssl`.
5849
after which the certificate expires.
5950
The sample below also assumes that you are using `cluster.local` as the default
6051
DNS domain name.
52+
53+
./easyrsa --subject-alt-name="IP:${MASTER_IP},"\
54+
"IP:${MASTER_CLUSTER_IP},"\
55+
"DNS:kubernetes,"\
56+
"DNS:kubernetes.default,"\
57+
"DNS:kubernetes.default.svc,"\
58+
"DNS:kubernetes.default.svc.cluster,"\
59+
"DNS:kubernetes.default.svc.cluster.local" \
60+
--days=10000 \
61+
build-server-full server nopass
62+
1. Copy `pki/ca.crt`, `pki/issued/server.crt`, and `pki/private/server.key` to your directory.
63+
1. Fill in and add the following parameters into the API server start parameters:
64+
65+
--client-ca-file=/yourdirectory/ca.crt
66+
--tls-cert-file=/yourdirectory/server.crt
67+
--tls-private-key-file=/yourdirectory/server.key
6168
-->
6269

70+
1. 下载、解压并初始化 easyrsa3 的补丁版本。
71+
72+
curl -LO https://storage.googleapis.com/kubernetes-release/easy-rsa/easy-rsa.tar.gz
73+
tar xzf easy-rsa.tar.gz
74+
cd easy-rsa-master/easyrsa3
75+
./easyrsa init-pki
76+
1. 生成 CA(通过 `--batch` 参数设置自动模式。 通过 `--req-cn` 设置默认使用的 CN)
77+
78+
./easyrsa --batch "--req-cn=${MASTER_IP}@`date +%s`" build-ca nopass
6379
1. 生成服务器证书和密钥。
6480
参数 `--subject-alt-name` 设置了访问 API 服务器时可能使用的 IP 和 DNS 名称。 `MASTER_CLUSTER_IP`
6581
通常为 `--service-cluster-ip-range` 参数中指定的服务 CIDR 的 首个 IP 地址,`--service-cluster-ip-range` 同时用于
@@ -75,12 +91,6 @@ manually through `easyrsa`, `openssl` or `cfssl`.
7591
"DNS:kubernetes.default.svc.cluster.local" \
7692
--days=10000 \
7793
build-server-full server nopass
78-
79-
<!--
80-
1. Copy `pki/ca.crt`, `pki/issued/server.crt`, and `pki/private/server.key` to your directory.
81-
1. Fill in and add the following parameters into the API server start parameters:
82-
-->
83-
8494
1. 拷贝 `pki/ca.crt``pki/issued/server.crt``pki/private/server.key` 至您的目录。
8595
1. 填充并在 API 服务器的启动参数中添加以下参数:
8696

@@ -94,40 +104,79 @@ manually through `easyrsa`, `openssl` or `cfssl`.
94104
**openssl** can manually generate certificates for your cluster.
95105
96106
1. Generate a ca.key with 2048bit:
97-
-->
98-
99-
使用 **openssl** 能够手动地为集群生成证书。
100-
101-
1. 生成密钥位数为 2048 的 ca.key:
102107
103108
openssl genrsa -out ca.key 2048
104-
105-
<!--
106109
1. According to the ca.key generate a ca.crt (use -days to set the certificate effective time):
107-
-->
108-
109-
1. 依据 ca.key 生成 ca.crt (使用 -days 参数来设置证书有效时间):
110110
111111
openssl req -x509 -new -nodes -key ca.key -subj "/CN=${MASTER_IP}" -days 10000 -out ca.crt
112-
113-
<!--
114112
1. Generate a server.key with 2048bit:
115-
-->
116-
117-
1. 生成密钥位数为 2048 的 server.key:
118113
119114
openssl genrsa -out server.key 2048
120-
121-
<!--
122115
1. Create a config file for generating a Certificate Signing Request (CSR).
123116
Be sure to substitute the values marked with angle brackets (e.g. `<MASTER_IP>`)
124117
with real values before saving this to a file (e.g. `csr.conf`).
125118
Note that the value for `MASTER_CLUSTER_IP` is the service cluster IP for the
126119
API server as described in previous subsection.
127120
The sample below also assumes that you are using `cluster.local` as the default
128121
DNS domain name.
122+
123+
[ req ]
124+
default_bits = 2048
125+
prompt = no
126+
default_md = sha256
127+
req_extensions = req_ext
128+
distinguished_name = dn
129+
130+
[ dn ]
131+
C = <country>
132+
ST = <state>
133+
L = <city>
134+
O = <organization>
135+
OU = <organization unit>
136+
CN = <MASTER_IP>
137+
138+
[ req_ext ]
139+
subjectAltName = @alt_names
140+
141+
[ alt_names ]
142+
DNS.1 = kubernetes
143+
DNS.2 = kubernetes.default
144+
DNS.3 = kubernetes.default.svc
145+
DNS.4 = kubernetes.default.svc.cluster
146+
DNS.5 = kubernetes.default.svc.cluster.local
147+
IP.1 = <MASTER_IP>
148+
IP.2 = <MASTER_CLUSTER_IP>
149+
150+
[ v3_ext ]
151+
authorityKeyIdentifier=keyid,issuer:always
152+
basicConstraints=CA:FALSE
153+
keyUsage=keyEncipherment,dataEncipherment
154+
extendedKeyUsage=serverAuth,clientAuth
155+
subjectAltName=@alt_names
156+
1. Generate the certificate signing request based on the config file:
157+
158+
openssl req -new -key server.key -out server.csr -config csr.conf
159+
1. Generate the server certificate using the ca.key, ca.crt and server.csr:
160+
161+
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
162+
-CAcreateserial -out server.crt -days 10000 \
163+
-extensions v3_ext -extfile csr.conf
164+
1. View the certificate:
165+
166+
openssl x509 -noout -text -in ./server.crt
129167
-->
130168

169+
使用 **openssl** 能够手动地为集群生成证书。
170+
171+
1. 生成密钥位数为 2048 的 ca.key:
172+
173+
openssl genrsa -out ca.key 2048
174+
1. 依据 ca.key 生成 ca.crt (使用 -days 参数来设置证书有效时间):
175+
176+
openssl req -x509 -new -nodes -key ca.key -subj "/CN=${MASTER_IP}" -days 10000 -out ca.crt
177+
1. 生成密钥位数为 2048 的 server.key:
178+
179+
openssl genrsa -out server.key 2048
131180
1. 创建用于生成证书签名请求(CSR)的配置文件。
132181
确保在将其保存至文件(如 `csr.conf`)之前将尖括号标记的值(如 `<MASTER_IP>`
133182
替换为你想使用的真实值。 注意:`MASTER_CLUSTER_IP` 是前面小节中描述的 API 服务器的服务集群 IP
@@ -166,29 +215,14 @@ manually through `easyrsa`, `openssl` or `cfssl`.
166215
keyUsage=keyEncipherment,dataEncipherment
167216
extendedKeyUsage=serverAuth,clientAuth
168217
subjectAltName=@alt_names
169-
170-
<!--
171-
1. Generate the certificate signing request based on the config file:
172-
-->
173-
174218
1. 基于配置文件生成证书签名请求:
175219

176220
openssl req -new -key server.key -out server.csr -config csr.conf
177-
178-
<!--
179-
1. Generate the server certificate using the ca.key, ca.crt and server.csr:
180-
-->
181-
182221
1. 使用 ca.key、ca.crt 和 server.csr 生成服务器证书:
183222

184223
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
185224
-CAcreateserial -out server.crt -days 10000 \
186225
-extensions v3_ext -extfile csr.conf
187-
188-
<!--
189-
1. View the certificate:
190-
-->
191-
192226
1. 查看证书:
193227

194228
openssl x509 -noout -text -in ./server.crt
@@ -211,34 +245,20 @@ Finally, add the same parameters into the API server start parameters.
211245
1. Download, unpack and prepare the command line tools as shown below.
212246
Note that you may need to adapt the sample commands based on the hardware
213247
architecture and cfssl version you are using.
214-
-->
215248
216-
1. 按如下所示的方式下载、解压并准备命令行工具。
217-
注意:你可能需要基于硬件架构和你所使用的 cfssl 版本对示例命令进行修改。
218-
219-
curl -L https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 -o cfssl
249+
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssl_1.4.1_linux_amd64 -o cfssl
220250
chmod +x cfssl
221-
curl -L https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -o cfssljson
251+
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssljson_1.4.1_linux_amd64 -o cfssljson
222252
chmod +x cfssljson
223-
curl -L https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 -o cfssl-certinfo
253+
curl -L https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssl-certinfo_1.4.1_linux_amd64 -o cfssl-certinfo
224254
chmod +x cfssl-certinfo
225-
226-
<!--
227255
1. Create a directory to hold the artifacts and initialize cfssl:
228-
-->
229-
230-
1. 创建目录来存放物料,并初始化 cfssl:
231256
232257
mkdir cert
233258
cd cert
234259
../cfssl print-defaults config > config.json
235260
../cfssl print-defaults csr > csr.json
236-
237-
<!--
238261
1. Create a JSON config file for generating the CA file, for example, `ca-config.json`:
239-
-->
240-
241-
1. 创建用来生成 CA 文件的 JSON 配置文件,例如 `ca-config.json`
242262
243263
{
244264
"signing": {
@@ -258,15 +278,9 @@ Finally, add the same parameters into the API server start parameters.
258278
}
259279
}
260280
}
261-
262-
<!--
263281
1. Create a JSON config file for CA certificate signing request (CSR), for example,
264282
`ca-csr.json`. Be sure to replace the values marked with angle brackets with
265283
real values you want to use.
266-
-->
267-
268-
1. 创建用来生成 CA 证书签名请求(CSR)的 JSON 配置文件,例如 `ca-csr.json`
269-
确保将尖括号标记的值替换为你想使用的真实值。
270284
271285
{
272286
"CN": "kubernetes",
@@ -282,24 +296,103 @@ Finally, add the same parameters into the API server start parameters.
282296
"OU": "<organization unit>"
283297
}]
284298
}
285-
286-
<!--
287299
1. Generate CA key (`ca-key.pem`) and certificate (`ca.pem`):
288-
-->
289-
290-
1. 生成 CA 密钥(`ca-key.pem`)和证书(`ca.pem`):
291300
292301
../cfssl gencert -initca ca-csr.json | ../cfssljson -bare ca
293-
294-
<!--
295302
1. Create a JSON config file for generating keys and certificates for the API
296303
server, for example, `server-csr.json`. Be sure to replace the values in angle brackets with
297304
real values you want to use. The `MASTER_CLUSTER_IP` is the service cluster
298305
IP for the API server as described in previous subsection.
299306
The sample below also assumes that you are using `cluster.local` as the default
300307
DNS domain name.
308+
309+
{
310+
"CN": "kubernetes",
311+
"hosts": [
312+
"127.0.0.1",
313+
"<MASTER_IP>",
314+
"<MASTER_CLUSTER_IP>",
315+
"kubernetes",
316+
"kubernetes.default",
317+
"kubernetes.default.svc",
318+
"kubernetes.default.svc.cluster",
319+
"kubernetes.default.svc.cluster.local"
320+
],
321+
"key": {
322+
"algo": "rsa",
323+
"size": 2048
324+
},
325+
"names": [{
326+
"C": "<country>",
327+
"ST": "<state>",
328+
"L": "<city>",
329+
"O": "<organization>",
330+
"OU": "<organization unit>"
331+
}]
332+
}
333+
1. Generate the key and certificate for the API server, which are by default
334+
saved into file `server-key.pem` and `server.pem` respectively:
335+
336+
../cfssl gencert -ca=ca.pem -ca-key=ca-key.pem \
337+
--config=ca-config.json -profile=kubernetes \
338+
server-csr.json | ../cfssljson -bare server
301339
-->
302340

341+
1. 按如下所示的方式下载、解压并准备命令行工具。
342+
注意:你可能需要基于硬件架构和你所使用的 cfssl 版本对示例命令进行修改。
343+
344+
curl -L https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 -o cfssl
345+
chmod +x cfssl
346+
curl -L https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 -o cfssljson
347+
chmod +x cfssljson
348+
curl -L https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64 -o cfssl-certinfo
349+
chmod +x cfssl-certinfo
350+
1. 创建目录来存放物料,并初始化 cfssl:
351+
352+
mkdir cert
353+
cd cert
354+
../cfssl print-defaults config > config.json
355+
../cfssl print-defaults csr > csr.json
356+
1. 创建用来生成 CA 文件的 JSON 配置文件,例如 `ca-config.json`
357+
358+
{
359+
"signing": {
360+
"default": {
361+
"expiry": "8760h"
362+
},
363+
"profiles": {
364+
"kubernetes": {
365+
"usages": [
366+
"signing",
367+
"key encipherment",
368+
"server auth",
369+
"client auth"
370+
],
371+
"expiry": "8760h"
372+
}
373+
}
374+
}
375+
}
376+
1. 创建用来生成 CA 证书签名请求(CSR)的 JSON 配置文件,例如 `ca-csr.json`
377+
确保将尖括号标记的值替换为你想使用的真实值。
378+
379+
{
380+
"CN": "kubernetes",
381+
"key": {
382+
"algo": "rsa",
383+
"size": 2048
384+
},
385+
"names":[{
386+
"C": "<country>",
387+
"ST": "<state>",
388+
"L": "<city>",
389+
"O": "<organization>",
390+
"OU": "<organization unit>"
391+
}]
392+
}
393+
1. 生成 CA 密钥(`ca-key.pem`)和证书(`ca.pem`):
394+
395+
../cfssl gencert -initca ca-csr.json | ../cfssljson -bare ca
303396
1. 按如下所示的方式创建用来为 API 服务器生成密钥和证书的 JSON 配置文件。
304397
确保将尖括号标记的值替换为你想使用的真实值。 `MASTER_CLUSTER_IP` 是前面小节中描述的
305398
API 服务器的服务集群 IP。 下面的示例也假设用户使用 `cluster.local` 作为默认的 DNS 域名。
@@ -328,12 +421,6 @@ Finally, add the same parameters into the API server start parameters.
328421
"OU": "<organization unit>"
329422
}]
330423
}
331-
332-
<!--
333-
1. Generate the key and certificate for the API server, which are by default
334-
saved into file `server-key.pem` and `server.pem` respectively:
335-
-->
336-
337424
1. 为 API 服务器生成密钥和证书,生成的秘钥和证书分别默认保存在文件 `server-key.pem`
338425
`server.pem` 中:
339426

0 commit comments

Comments
 (0)