セットアップ

Edit This Page

PKI証明書とその要件

Kubernetes requires PKI certificates for authentication over TLS. If you install Kubernetes with kubeadm, the certificates that your cluster requires are automatically generated. You can also generate your own certificates – for example, to keep your private keys more secure by not storing them on the API server. This page explains the certificates that your cluster requires.

あなたのクラスタではどのように証明書が使われているのか

Kubernetes requires PKI for the following operations:

Note: front-proxy certificates are required only if you run kube-proxy to support an extension API server.

etcd also implements mutual TLS to authenticate clients and peers.

証明書の保存場所

If you install Kubernetes with kubeadm, certificates are stored in /etc/kubernetes/pki. All paths in this documentation are relative to that directory.

手動で証明書を設定する

If you don’t want kubeadm to generate the required certificates, you can create them in either of the following ways.

単一ルート認証局

You can create a single root CA, controlled by an administrator. This root CA can then create multiple intermediate CAs, and delegate all further creation to Kubernetes itself.

Required CAs:

pathDefault CNdescription
ca.crt,keykubernetes-caKubernetes general CA
etcd/ca.crt,keyetcd-caFor all etcd-related functions
front-proxy-ca.crt,keykubernetes-front-proxy-caFor the front-end proxy

全ての証明書

If you don’t wish to copy these private keys to your API servers, you can generate all certificates yourself.

Required certificates:

Default CNParent CAO (in Subject)kindhosts (SAN)
kube-etcdetcd-caserver, client [1][etcdbug]localhost, 127.0.0.1
kube-etcd-peeretcd-caserver, client<hostname>, <Host_IP>, localhost, 127.0.0.1
kube-etcd-healthcheck-clientetcd-caclient
kube-apiserver-etcd-clientetcd-casystem:mastersclient
kube-apiserverkubernetes-caserver<hostname>, <Host_IP>, <advertise_IP>, [1]
kube-apiserver-kubelet-clientkubernetes-casystem:mastersclient
front-proxy-clientkubernetes-front-proxy-caclient

[1]: kubernetes, kubernetes.default, kubernetes.default.svc, kubernetes.default.svc.cluster, kubernetes.default.svc.cluster.local

where kind maps to one or more of the x509 key usage types:

kindKey usage
serverdigital signature, key encipherment, server auth
clientdigital signature, key encipherment, client auth

証明書のパス

Certificates should be placed in a recommended path (as used by kubeadm). Paths should be specified using the given argument regardless of location.

Default CNrecommend key pathrecommended cert pathcommandkey argumentcert argument
etcd-caetcd/ca.crtkube-apiserver–etcd-cafile
etcd-clientapiserver-etcd-client.crtapiserver-etcd-client.crtkube-apiserver–etcd-certfile–etcd-keyfile
kubernetes-caca.crtkube-apiserver–client-ca-file
kube-apiserverapiserver.crtapiserver.keykube-apiserver–tls-cert-file–tls-private-key
apiserver-kubelet-clientapiserver-kubelet-client.crtkube-apiserver–kubelet-client-certificate
front-proxy-clientfront-proxy-client.keyfront-proxy-client.crtkube-apiserver–proxy-client-cert-file–proxy-client-key-file
etcd-caetcd/ca.crtetcd–trusted-ca-file, –peer-trusted-ca-file
kube-etcdetcd/server.crtetcd–cert-file
kube-etcd-peeretcd/peer.keyetcd/peer.crtetcd–peer-key-file–peer-cert-file
etcd-caetcd/ca.crtetcdctl[2]–cacert
kube-etcd-healthcheck-clientetcd/healthcheck-client.keyetcd/healthcheck-client.crtetcdctl[2]–key–cert

[2]: For a liveness probe, if self-hosted

ユーザアカウント用に証明書を設定する

You must manually configure these administrator account and service accounts:

filenamecredential nameDefault CNO (in Subject)
admin.confdefault-adminkubernetes-adminsystem:masters
kubelet.confdefault-authsystem:node:<nodename>system:nodes
controller-manager.confdefault-controller-managersystem:kube-controller-manager
scheduler.confdefault-managersystem:kube-scheduler
  1. For each config, generate an x509 cert/key pair with the given CN and O.

  2. Run kubectl as follows for each config:

KUBECONFIG=<filename> kubectl config set-cluster default-cluster --server=https://<host ip>:6443 --certificate-authority <path-to-kubernetes-ca> --embed-certs
KUBECONFIG=<filename> kubectl config set-credentials <credential-name> --client-key <path-to-key>.pem --client-certificate <path-to-cert>.pem --embed-certs
KUBECONFIG=<filename> kubectl config set-context default-system --cluster default-cluster --user <credential-name>
KUBECONFIG=<filename> kubectl config use-context default-system

These files are used as follows:

filenamecommandcomment
admin.confkubectlConfigures administrator user for the cluster
kubelet.confkubeletOne required for each node in the cluster.
controller-manager.confkube-controller-managerMust be added to manifest in manifests/kube-controller-manager.yaml
scheduler.confkube-schedulerMust be added to manifest in manifests/kube-scheduler.yaml

Feedback