当前位置: 首页 > news >正文

OKE 安装 Nginx Ingress 配置应用 TLS 证书

OKE 安装 Nginx Ingress && 配置应用 TLS 证书

在这里插入图片描述

1 安装 Nginx Ingress controller

示例:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v<vnum>/deploy/static/provider/cloud/deploy.yaml
  • 其中 是ingress的版本,大家可以参考 nginx ingress 官方找寻自己的示例

nginx ingress 官方地址:https://github.com/kubernetes/ingress-nginx?tab=readme-ov-file#supported-versions-table

2 安装后查看 ingress

2.1 查看svc创建状态

kubectl get svc -n ingress-nginx

2.2 结果展示

当前状态表示正在创建中,EXTERNAL-IP 的pending状态表示 OKE 正在为当前svc分配负载均衡 IP

NAME                       TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)                       AGE
ingress-nginx-controller   LoadBalancer   10.96.229.38   <pending>      80:30756/TCP,443:30118/TCP    1h

2.3 持续展示

如下结果中 EXTERNAL-IP 列已经显示出 IP, 表示当前 ingress 已经完成了映射

NAME                       TYPE           CLUSTER-IP     EXTERNAL-IP       PORT(S)                       AGE
ingress-nginx-controller   LoadBalancer   10.96.229.38   129.146.214.219   80:30756/TCP,443:30118/TCP    1h

3 创建 TLS Secret

3.1 自签名方式创建KEY

示例采用自签名方式进行配置

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=nginxsvc/O=nginxsvc"

3.2 TLS 添加 Secret 中

kubectl create secret tls tls-secret --key tls.key --cert tls.crt

4 创建示例后端集

4.1 创建 Deployment hello-world 示例


### vim hello-world-ingress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-hello-world
  labels:
    app: docker-hello-world
spec:
  selector:
    matchLabels:
      app: docker-hello-world
  replicas: 3
  template:
    metadata:
      labels:
        app: docker-hello-world
    spec:
      containers:
      - name: docker-hello-world
        image: scottsbaldwin/docker-hello-world:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: docker-hello-world-svc
spec:
  selector:
    app: docker-hello-world
  ports:
    - port: 8088
      targetPort: 80
  type: ClusterIP

4.2 部署示例

kubectl create -f hello-world-ingress.yaml

5 配置 Ingress 分发

5.1 配置 ingress .yaml

### vim ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ing
spec:
  ingressClassName: nginx
  tls:
  - secretName: tls-secret
  rules:
  - http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: docker-hello-world-svc
              port:
                number: 8088

5.2 应用 ingress 配置

kubectl create -f ingress.yaml

6 测试结果

$ curl -k https://129.146.214.219

<h1>Hello webhook world from: docker-hello-world-1732906117-6115l</h1>

$ curl -k https://129.146.214.219

<h1>Hello webhook world from: docker-hello-world-1732906117-7r89v</h1>

$ curl -k https://129.146.214.219

<h1>Hello webhook world from: docker-hello-world-1732906117-0ztkm</h1>

7 参考资料

https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengsettingupingresscontroller.htm#Example_Setting_Up_an_Ingress_Controller_on_a_Cluster

相关文章:

  • 视频流畅播放相关因素
  • 磁盘空间不足|如何安全清理以释放磁盘空间(开源+节流)
  • 天佐.混沌钟 软件许可授权
  • 【开源项目】好用的开源项目记录(持续更新)
  • 【C++】深入理解const成员
  • Windows平台调试器原理与编写03.单步
  • KVM虚拟机磁盘创建探究-1
  • Redis面试篇笔记:
  • 单例模式(线程案例)
  • 失去的讨论区
  • PySide(PyQT)的信号槽框架的一个demo练习
  • Spring Boot 简介与快速搭建及启动流程详解
  • 剑指 Offer II 041. 滑动窗口的平均值
  • 用pytest进行单元测试(1)
  • SpringBoot @ConfigurationProperties 注解使用
  • 2025.3.3
  • 聊聊学习之数据-信息-知识-洞见-智慧-影响力
  • 【PTA】1019 数字黑洞
  • 绘制思维导图画布选型
  • 【OMCI实践】omci.lua脚本文件(独家分享)
  • 李铁案二审今日宣判
  • A股三大股指小幅低收:电力股大幅调整,两市成交10221亿元
  • 4月人文社科联合书单|天文学家的椅子
  • 监狱法修订草案提请全国人大常委会会议审议
  • 传智教育连续3个交易日跌停:去年净利润由盈转亏
  • 人民日报:应对外贸行业风险挑战,稳企业就是稳就业