背景

k8s 的dashboard默认要用https访问,内网环境可以直接访问ip+port,现在需要通过nginx代理,让外网访问。所以这里用到自制证书代理k8s dashboard。

制作证书过程

  1. 生成key文件
$ openssl genrsa -out dashboard.key 1024
Generating RSA private key, 1024 bit long modulus
.................................................................++++++
.++++++
e is 65537 (0x10001)
  1. 填写信息生成csr文件
$ openssl req -new -key dashboard.key -out dashboard.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:ah
Locality Name (eg, city) [Default City]:hf
Organization Name (eg, company) [Default Company Ltd]:hf
Organizational Unit Name (eg, section) []:hf
Common Name (eg, your name or your server's hostname) []:dashboard.elliot.com
Email Address []:elliot@163.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

这里填写你的域名:Common Name (eg, your name or your server's hostname) []:dashboard.elliot.com
最后两行password,直接回车
3. 生成crt文件

$ openssl x509 -req -days 3650 -in dashboard.csr -signkey dashboard.key -out dashboard.crt
Signature ok
subject=/C=cn/ST=ah/L=hf/O=hf/OU=hf/CN=dashboard.upower.com/emailAddress=elliot@163.com
Getting Private key

此时,当前目录有了3个文件

$ ls
dashboard.csr  dashboard.key dashboard.crt
  1. 修改nginx文件
    server {               
        listen   443    ssl;
        server_name dashboard.elliot.com;
        ssl_certificate /etc/nginx/conf.d/ssl/dashboard.crt;
        ssl_certificate_key /etc/nginx/conf.d/ssl/dashboard.key;       
        ssl_session_cache  shared:SSL:1m;
        ssl_session_timeout 5m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;