k8s 给服务设置https访问

查看Pod

 kubectl get pods -n <名称空间名> 

查看 Ingress 配置

kubectl get ingresses -n <ingress 名> 

查看 Ingress 相关Pod的分布情况

kubectl get pod -o wide -n ingress-nginx 

查看 Ingress Pod 的配置文件

kubectl get pod nginx-ingress-controller-fvcvx -o yaml -n ingress-nginx 

查看 Ingress 的配置文件

kubectl get ing -o yaml -n po-ams 

编辑 Ingress 配置文件

kubectl edit ing -n po-ams  编辑的命令是 kubectl edit ing -n po-ams   

查看日志

kubectl logs -n po-ams po-ams-ser-6cdcd79b4d-xmsnm 

配置ingress https 访问

  • 利用证书申请下来的公钥和私钥 创建secret密钥
kubectl create secret tls tls-secret --key tls.key --cert tls.crt
  • 编辑 Ingress 配置文件
kubectl edit ing -n po-ams
spec:
  tls: # 创建tls
    - hosts: # 下面指定域名 
      - nginx.itheima.com
      - tomcat.itheima.com
      secretName: tls-secret # 指定秘钥  

保存

  • 查看转发规则
[root@k8s-master01 ~]# kubectl describe ing ingress-https -n dev
...
TLS:
  tls-secret terminates nginx.itheima.com,tomcat.itheima.com 
Rules:
Host              Path Backends
----              ---- --------
nginx.itheima.com  /  nginx-service:80 (10.244.1.97:80,10.244.1.98:80,10.244.2.119:80)
tomcat.itheima.com /  tomcat-service:8080(10.244.1.99:8080,10.244.2.117:8080,10.244.2.120:8080)
...
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐