005_部署nginx-ingress

关于我们

https://yuemake.xyz
公众号: 悦码客
v: ymkcode
视频教程:https://www.bilibili.com/video/BV1bG411M7we?vd_source=2d319a7a197bc133da44d00cd53e970c

专注方向:
自动化流程服务
it咨询
it在线教学

doc

https://kubernetes.io/docs/concepts/services-networking/ingress/

介绍

Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.

ingress 暴露了 从 外部 到 集群 内部服务 的 http/https 路由。 流量路由被 ingress 资源定义的规则所控制。

必要条件

You must have an Ingress controller to satisfy an Ingress. Only creating an Ingress resource has no effect.

You may need to deploy an Ingress controller such as ingress-nginx. You can choose from a number of Ingress controllers.

Ideally, all Ingress controllers should fit the reference specification. In reality, the various Ingress controllers operate slightly differently.

你必须拥有一个 ingress 控制器 去满足一个ingress。 仅仅创建一个 ingress 资源 是没有作用的。

你可能 需要部署一个 ingress 控制器, 比如 ingress-nginx。 你能选择一系列的ingress 控制器。

理想情况中,所有的 ingress 控制器 都必须满足 参考规范。 现实中,不同的 ingress 控制器的 操作 拥有 轻微的不同。

验证

配置访问 nginx-lb 服务
k8s\deploy\config\ingress\resource.yaml

配置访问 https openldap 服务
k8s\yamls\openldap\ingress-resource.yaml

参考

k8s\deploy\config\ingress

doc

https://kubernetes.github.io/ingress-nginx/deploy/

获取镜像


host_ip=192.168.31.21
export  http_proxy="http://${host_ip}:7890"
export  https_proxy="http://${host_ip}:7890"
export  no_proxy="localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local,my-cluster-endpoint.com"

imgs=(
    registry.k8s.io/ingress-nginx/controller:v1.5.1@sha256:4ba73c697770664c1e00e9f968de14e08f606ff961c76e5d7033a4a9c593c629
    registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20220916-gd32f8c343@sha256:39c5b2e3310dc4264d638ad28d9d1d96c4cbb2b2dcfb52368fe4e3c63f61e10f
)

function pull_img(){
    ctr -n k8s.io images pull ${1}
}

for i in ${imgs[@]}
do
    echo "pull: $i"
    pull_img $i &
done

部署

ingress controller

https://kubernetes.github.io/ingress-nginx/deploy/#quick-start

部署控制器,负责将 ingress resource 流量 冲定向 到 内部 service

# https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.5.1/deploy/static/provider/cloud/deploy.yaml

cd /git_proj/blogs/k8s/deploy/config/ingress
kubectl apply -f deploy.yaml

kubectl -n  ingress-nginx  get svc
# NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)                      AGE
# ingress-nginx-controller             LoadBalancer   10.109.70.188    192.168.31.226   80:32141/TCP,443:31269/TCP   52m

# 访问 nginx controller
192.168.31.241

ingress resource

https://kubernetes.io/docs/concepts/services-networking/ingress/

ingress controller 可以部署在任意的 namespace。

ingress resource 定义的 ingress 对象必须和 被 路由的 服务 位于 相同的 namespace


cd /git_proj/blogs/k8s/deploy/config/ingress
kubectl apply -f resource.yaml

# 查询 ingress resource list
kubectl -n  nginx-lb get ingress
# NAME              CLASS   HOSTS   ADDRESS   PORTS   AGE
# minimal-ingress   nginx   *                 80      19s

# 查询某个 ingress resource 的详细状态
kubectl -n  nginx-lb describe ingress  minimal-ingress

# 
# 192.168.31.241
# ingress controller
http://ingress.dev.inner.ymk.com

# my test nginx
http://ingress.dev.inner.ymk.com/testpath

# dns test
nslookup ingress.dev.inner.ymk.com
# 服务器:  UnKnown
# Address:  192.168.31.234

# 名称:    ingress.dev.inner.ymk.com
# Address:  192.168.31.241

delpoy.yaml

https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.5.1/deploy/static/provider/cloud/deploy.yaml

resource.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: nginx-lb
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: nginx-lb
            port:
              number: 80

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuemake999

请我喝茶呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值