k8s配置ingress的https访问


一、部署步骤

1、安装nginx-ingress-controller

2、创建secret绑定证书

3、创建测试服务

4、创建ingress

5、测试https访问

 

二、安装nginx-ingress-controller

1、部署helm

[root@master ~]# wget https://get.helm.sh/helm-v3.7.2-linux-amd64.tar.gz
[root@master ~]# tar zxvf helm-v3.7.2-linux-amd64.tar.gz
[root@master ~]# cp linux-amd64/helm /usr/local/bin/

 

2、添加helm chat

[root@master ~]# helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

 

3、添加标签

[root@master ~]# kubectl label nodes nodename node=ingress

nodename修改为部署ingress-nginx-controller的节点名称


4、部署nginx-ingress-controller

helm install nginx-ingress ingress-nginx/ingress-nginx   --namespace ingress-nginx   --create-namespace   --set controller.image.registry=willdockerhub   --set controller.image.image=ingress-nginx-controller   --set controller.image.tag=v1.0.0   --set controller.image.digest=""   --set controller.hostNetwork=true   --set controller.kind=DaemonSet   --set controller.service.type=ClusterIP   --set controller.hostPort.enable=true   --set controller.admissionWebhooks.enabled=false --set controller.hostPort.http=80   --set controller.hostPort.https=443   --set controller.nodeSelector.node=ingress

 

5、查看80、443是否开放

[root@master ~]# kubectl get pod -n ingress-nginx -o wide

 

 登录node显示的controller部署节点执行以下命令查看端口是否开放

[root@master ~]# ss -anp|grep :443

 

 

三、创建secret绑定证书

1、申请阿里云SSL证书

2、创建secret绑定证书

[root@master ~]# kubectl create secret tls ingress-secret --key=6839102_test.k8sstudy.online.key --cert=6839102_test.k8sstudy.online.pem -n kube-system

 

四、创建测试服务

1、准备yaml文件

[root@master ~]# cat >>hello-world.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: helloworld-nodejs
  name: helloworld-nodejs
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld-nodejs
  template:
    metadata:
      labels:
        app: helloworld-nodejs
    spec:
      containers:
      - image: docker.io/xzxiaoshan/helloworld-nodejs:latest
        name: helloworld-nodejs
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: helloworld-nodejs
  namespace: kube-system
spec:
  selector:
      app: helloworld-nodejs
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 8080
    - name: https
      port: 443
      protocol: TCP
      targetPort: 8080
EOF

 

2、创建测试服务

[root@master ~]# kubectl apply -f hello-world.yaml

 

五、创建ingress

1、准备yaml文件

[root@master ~]# cat >>ingress.yaml<<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-world
  namespace: kube-system
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  rules:
  - host: test.k8sstudy.online
    http:
      paths:
      - backend:
          serviceName: helloworld-nodejs
          servicePort: 80
        path: /
  tls:
  - hosts:
    - test.k8sstudy.online
    secretName: hello-world-secret
EOF

 2、创建ingress

[root@master ~]# kubectl apply -f ingress.yaml

 

六、测试https访问

 1、配置hosts解析

Windows配置路径:C:\Windows\System32\drivers\etc\hosts

2、浏览器访问

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM