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'


相关推荐
昌sit!12 分钟前
K8S node节点没有相应的pod镜像运行故障处理办法
云原生·容器·kubernetes
A ?Charis3 小时前
Gitlab-runner running on Kubernetes - hostAliases
容器·kubernetes·gitlab
wclass-zhengge3 小时前
Docker篇(Docker Compose)
运维·docker·容器
茶馆大橘3 小时前
微服务系列五:避免雪崩问题的限流、隔离、熔断措施
java·jmeter·spring cloud·微服务·云原生·架构·sentinel
北漂IT民工_程序员_ZG4 小时前
k8s集群安装(minikube)
云原生·容器·kubernetes
coding侠客4 小时前
揭秘!微服务架构下,Apollo 配置中心凭啥扮演关键角色?
微服务·云原生·架构
梦魇梦狸º7 小时前
腾讯轻量云服务器docker拉取不到镜像的问题:拉取超时
docker·容器·github
南猿北者9 小时前
docker镜像仓库常用命令
运维·docker·容器
2301_8061313610 小时前
Kubernetes的基本构建块和最小可调度单元pod-0
云原生·容器·kubernetes
SilentCodeY11 小时前
containerd配置私有仓库registry
容器·kubernetes·containerd·镜像·crictl