安装openssl
Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions
生成证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout example.local.key -out example.local.crt -subj "/CN=example.local/O=example.local"
创建K8S secret
kubectl create secret tls example-local-tls --key example.local.key --cert example.local.crt
查看
kubectl get secret example-local-tls -o yaml
创建SSL转发
nginx-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx-ingressannotations:nginx.ingress.kubernetes.io/rewrite-target: /
spec:ingressClassName: nginxrules:- host: example.localhttp:paths:- path: /pathType: Prefixbackend:service:name: nginx-serviceport:number: 80tls:- hosts:- example.localsecretName: example-local-tls
kubectl apply -f nginx-ingress.yaml
访问
https://example.local/
查看ingress转发日志
kubectl get pods -n ingress-nginx
kubectl logs -n ingress-nginx ingress-nginx-controller-5b5f8c9f5d-abcdef