# Bootstrap a simple internal CA in Kubernetes with cert-manager.
# Use the SelfSigned issuer only to create the initial root CA.
# Then switch normal issuance to the CA issuer.
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: bootstrap-selfsigned
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: internal-root-ca
  namespace: cert-manager
spec:
  isCA: true
  commonName: internal-root-ca
  secretName: internal-root-ca
  duration: 87600h # 10y; keep root usage rare and protected
  privateKey:
    algorithm: ECDSA
    size: 256
  issuerRef:
    name: bootstrap-selfsigned
    kind: ClusterIssuer
    group: cert-manager.io
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: internal-ca
spec:
  ca:
    secretName: internal-root-ca
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: payments-api-tls
  namespace: payments
spec:
  secretName: payments-api-tls
  duration: 168h # 7d leaf cert
  renewBeforePercentage: 30
  privateKey:
    rotationPolicy: Always
    algorithm: ECDSA
    size: 256
  dnsNames:
    - payments-api.payments.svc.cluster.local
    - payments-api.payments
  issuerRef:
    name: internal-ca
    kind: ClusterIssuer
    group: cert-manager.io
  usages:
    - server auth
    - client auth
