k8s 使用cert-manager证书管理自签

个人建议使用安装更快,比helm快,还要等待安装crd

js 复制代码
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.3/cert-manager.yaml
js 复制代码
#官网
https://cert-manager.io/docs/installation/kubectl/
js 复制代码
#创建自签的ClusterIssuer
cat >  signing-custom.yaml <<-EOF
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: selfsigned-clusterissuer
spec:
  selfSigned: {}

---
#生成证书
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: java-selfsigned-ca
  namespace: cert-manager
spec:
  isCA: true
  commonName: java-selfsigned-ca
  secretName: java-selfsigned-secret # 生成的证书名
  duration: 360h
  privateKey:
    algorithm: ECDSA
    size: 256
  issuerRef:
    name: selfsigned-clusterissuer # 对应上面清单中创建的clusterissuer名称
    kind: ClusterIssuer
    group: cert-manager.io
---
#生成以这个证书作为CA的ClusterIssuer,其他证书由这个CA签发
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: my-ca-issuer
spec:
  ca:
    secretName: java-selfsigned-secret # 对应以上Certificate资源证书名
EOF

查看你的证书

js 复制代码
kubectl get clusterissuers,certificate
kubectl -n cert-manager get secret

手动签发ssl自签证书

js 复制代码
cat > server-tls.yaml  <<-EOF
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: java-com
spec:
  secretName: java-tls
  duration: 12160h # 你想要的时间
  renewBefore: 3600h #
  subject:
    organizations:
      - jetstack
  commonName: abc.exchangs.top
  isCA: false
  privateKey:
    algorithm: RSA
    encoding: PKCS1
    size: 2048
  usages:
    - server auth
    - client auth
  dnsNames:
    - exchangs.top
    - abc.exchangs.top
  ipAddresses:
    - 192.168.0.53
  issuerRef:
    name: my-ca-issuer # 指定上面创建好的用于签名的CA
    kind: ClusterIssuer
    group: cert-manager.io
EOF

最后ingress

js 复制代码
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: springboot-server
  #annotations:
    #cert-manager.io/cluster-issuer: "letsencrypt-prod"

spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - abc.exchangs.top
    - bbc.exchangs.top
    secretName: java-tls
  rules:
  - host: abc.exchangs.top
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: springboot-server
            port:
              number: 8080
  - host: bbc.exchangs.top
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: springboot-server
            port:
              number: 8080

最后访问

js 复制代码
curl -kivL -H 'Host: bbc.exchangs.top' 'https://192.168.0.53'


相关推荐
liux35286 分钟前
k8s之Ingress讲解
云原生·容器·kubernetes
阿里云云原生19 分钟前
函数计算支持热门 MCP Server 一键部署
云原生
阿里云云原生41 分钟前
AI 网关代理 LLMs 最佳实践
云原生
欧先生^_^2 小时前
docker的文件系统Overlay2
运维·docker·容器
小刘爱喇石( ˝ᗢ̈˝ )4 小时前
玛卡巴卡的k8s知识点问答题(六)
云原生·容器·kubernetes
rider1894 小时前
【1】搭建k8s集群系列(二进制部署)之系统初始化
云原生·容器·kubernetes
阳小江4 小时前
Docker知识点
运维·docker·容器
阿里云云原生4 小时前
仅3步!即刻拥有 QwQ-32B,性能比肩全球最强开源模型
前端·云原生
小刘爱喇石( ˝ᗢ̈˝ )6 小时前
玛卡巴卡的k8s知识点问答题(七)
云原生·容器·kubernetes