kubeasz/docs/op/ch_apiserver_cert.md

1.3 KiB
Raw Blame History

修改 APISERVERMASTER证书

kubeasz 创建集群后APISERVERMASTER证书默认 CN 包含如下域名IP:参见roles/kube-master/templates/kubernetes-csr.json.j2

  "hosts": [
    "127.0.0.1",
{% if groups['ex-lb']|length > 0 %}
    "{{ hostvars[groups['ex-lb'][0]]['EX_APISERVER_VIP'] }}",
{% endif %}
    "{{ inventory_hostname }}",
    "{{ CLUSTER_KUBERNETES_SVC_IP }}",
{% for host in MASTER_CERT_HOSTS %}
    "{{ host }}",
{% endfor %}
    "kubernetes",
    "kubernetes.default",
    "kubernetes.default.svc",
    "kubernetes.default.svc.cluster",
    "kubernetes.default.svc.cluster.local"
  ],

有的时候比如apiserver地址通过边界防火墙的NAT转换成公网IP访问或者需要添加公网域名访问我们需要在 APISERVERMASTER证书中添加一些域名或者IP,可以方便操作如下:

1.修改配置文件roles/kube-master/defaults/main.yml

# k8s 集群 master 节点证书配置可以添加多个ip和域名比如增加公网ip和域名
MASTER_CERT_HOSTS:
  - "10.1.1.1"
  - "k8s.test.io"
  #- "61.182.11.41"
  #- "www.test.com"

2.执行新证书生成即可

$ ansible-playbook 04.kube-master.yml -t change_cert
# 新证书生效需要重启kube-apiserver.service
$ ansible-playbook 04.kube-master.yml -t restart_master