ZBLOG

k3s 安装nginx版本的ingress

要在 k3s 中安装 nginx 版本的 Ingress,请按照以下步骤进行操作:

  1. 安装 Helm
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
  1. 添加 stable 的 Helm 仓库
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm repo update
  1. 安装 nginx-ingress 控制器
helm install nginx-ingress stable/nginx-ingress --set controller.publishService.enabled=true
  1. 等待一段时间,直到 ingress-controller 和 ingress-default-backend 这两个 pod 的状态变为 Running
kubectl get pods -n default -l app.kubernetes.io/name=ingress-nginx
  1. 部署一个示例应用程序,并使用 Ingress 将其暴露出来

例如,部署一个 hello-world 应用程序,并使用 Ingress 将其暴露在域名 example.com 下:

创建一个 Deployment

kubectl create deployment hello-world --image=gcr.io/google-samples/hello-app:1.0

创建一个 Service,并将它公开为 ClusterIP 类型

kubectl expose deployment hello-world --port=8080 --type=ClusterIP

创建一个 Ingress,将它绑定到 example.com 域名上,并指定 hello-world Service 作为后端服务

cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: hello-world
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: hello-world
          servicePort: 8080
EOF
  1. 在本地修改 hosts 文件,添加一条记录将 example.com 解析为 k3s 集群的 IP 地址

  2. 在浏览器中访问 http://example.com,应该能够看到 hello-world 应用程序的输出

注意:在生产环境中,请根据实际情况进行配置,并采取必要的安全措施。

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=1403

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?