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'


相关推荐
tntlbb3 小时前
Ubuntu20.4 VPN+Docker代理配置
运维·ubuntu·docker·容器
Gabriel_liao4 小时前
Docker安装Neo4j
docker·容器·neo4j
有一个好名字4 小时前
zookeeper分布式锁模拟12306买票
分布式·zookeeper·云原生
Anna_Tong7 小时前
云原生大数据计算服务 MaxCompute 是什么?
大数据·阿里云·云原生·maxcompute·odps
豆豆豆豆变7 小时前
Docker轻量级可视化工具Portainer
docker·容器·自动化运维
花晓木7 小时前
k8s etcd 数据损坏处理方式
容器·kubernetes·etcd
运维&陈同学7 小时前
【模块一】kubernetes容器编排进阶实战之基于velero及minio实现etcd数据备份与恢复
数据库·后端·云原生·容器·kubernetes·etcd·minio·velero
花晓木7 小时前
k8s备份 ETCD , 使用velero工具进行备份
容器·kubernetes·etcd
大熊程序猿7 小时前
xxl-job docker 安装
运维·docker·容器
liuxuzxx10 小时前
Istio-2:流量治理之简单负载均衡
云原生·kubernetes·istio