安装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-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- host: example.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
tls:
- hosts:
- example.local
secretName: 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