kubernetes 之ingress

1、Ingress组件介绍

  • Ingress解决的是新的服务加入后,域名和服务的对应问题,基本上是一个ingress的对象,通过yaml进行创建和更新进行加载。
  • Ingress Controller是将Ingress这种变化生成一段Nginx的配置,然后将这个配置通过Kubernetes API写到Nginx的Pod中,然后reload.

2、生成一个默认的后端,如果遇到解析不到的URL就转发到默认后端页面

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: default-http-backend
  labels:
    app: default-http-backend
  namespace: ingress-nginx
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: default-http-backend
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: default-http-backend
        # Any image is permissable as long as:
        # 1. It serves a 404 page at /
        # 2. It serves 200 on a /healthz endpoint
        image: registry.cn-hangzhou.aliyuncs.com/google_containers/defaultbackend:1.4
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: 10m
            memory: 20Mi
          requests:
            cpu: 10m
            memory: 20Mi
---

apiVersion: v1
kind: Service
metadata:
  name: default-http-backend
  namespace: ingress-nginx
  labels:
    app: default-http-backend
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: default-http-backend

[[email protected] Ingress]# kubectl create -f default-backend.yaml
deployment "default-http-backend" created
service "default-http-backend" created
[[email protected] Ingress]#

[[email protected] Ingress]# kubectl get pods -n ingress-nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE
default-http-backend-5d8887b7f-l8r29 1/1 Running 0 28s 10.0.91.6 192.168.10.221

3、部署Ingress Controller

[[email protected] Ingress]# cat nginx-ingress-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-lb
  labels:
    name: nginx-ingress-lb
  namespace: ingress-nginx
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: nginx-ingress-lb
      annotations:
        prometheus.io/port: ‘10254‘
        prometheus.io/scrape: ‘true‘
    spec:
      terminationGracePeriodSeconds: 60
      hostNetwork: true
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:0.8.3
        name: nginx-ingress-lb
        readinessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 10254
            scheme: HTTP
          initialDelaySeconds: 10
          timeoutSeconds: 1
        ports:
        - containerPort: 80
          hostPort: 80
        - containerPort: 443
          hostPort: 443
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: KUBERNETES_MASTER
            value: http://192.168.10.220:8080
        args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/default-http-backend
#        - --apiserver-host=http://192.168.10.220:8080

[[email protected] Ingress]# kubectl get pod -n ingress-nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE
default-http-backend-5d8887b7f-l8r29 1/1 Running 0 21m 10.0.91.6 192.168.10.221
nginx-ingress-lb-gj4sg 1/1 Running 0 1m 192.168.10.221 192.168.10.221

 

4、本实验通过nginx 容器,这里通过ingress 做入口访问svc

[[email protected] ~]# cat nginx-deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: ingress-nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.10
        ports:
        - containerPort: 80

[[email protected] ~]# kubectl create -f nginx-deployment.yaml

[[email protected] ~]# cat nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: ingress-nginx
labels:
app: nginx
spec:
ports:
- port: 88
targetPort: 80
selector:
app: nginx

[[email protected] ~]# kubectl create -f nginx-service.yaml

[[email protected] ~]# cat ingress-nginx.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginxservice
namespace: ingress-nginx
spec:
rules:
- host: test.io
http:
paths:
- path: /
backend:
serviceName: nginx-service
servicePort: 80
- path: /
# backend:
# serviceName: kubernetes-dashboard
# servicePort: 80
[[email protected] ~]# kubectl create -f ingress-nginx.yaml

本机写host 文件进行访问,外部写host 文件,指向node ip 即可

原文地址:https://www.cnblogs.com/hellojackyleon/p/8420911.html

时间: 2024-10-08 22:34:34

kubernetes 之ingress的相关文章

kubernetes nginx ingress 使用记录

前言 ingress是一种可以暴露k8s集群内部service的方式,用户编辑配置文件定义一个ingress资源即可实现外部网络访问内网service. ingress controller是来管理所有的Ingress的对象,ingress controller内部其实是一个nginx的容器,当ingress controll 通过与 Kubernetes API 交互,感知集群中Ingress规则变化时会按照模板文件生成nginx.conf文件,然后reload该配置文件. 相对于kubern

kubernetes之Ingress部署

1,如何访问K8S中的服务: 1,Ingress介绍 Kubernetes 暴露服务的方式目前只有三种:LoadBlancer Service.NodePort Service.Ingress:前两种估计都应该很熟悉,下面详细的了解下这个 Ingress Ingress由两部分组成:Ingress Controller 和 Ingress 服务. Ingress Contronler 通过与 Kubernetes API 交互,动态的去感知集群中 Ingress 规则变化,然后读取它,按照自定义

使用traefik作为kubernetes的ingress

[toc] 说明 关于kubernetes的服务暴露方式以及traefik的原理篇这里不作详细说明.traefik的原理可以参考官方文档:https://docs.traefik.io/ ,而关于kubernetes的服务暴露方式以及将traefik作为kubernetes的ingress使用的基本原理也可以参考这篇文档:https://mritd.me/2016/12/06/try-traefik-on-kubernetes/ .这篇文档主要阐述将traefik作为kubernetes的ing

Kubernetes之Ingress和Ingress Controller

目录 Kubernetes之Ingress和Ingress Controller 概念 Ingress资源类型 单Service资源型Ingress Ingress Nginx部署 部署Ingress controller 配置ingress后端服务 部署ingress-nginx service 部署Ingress 增加tomcat服务 总结 构建TLS站点 Kubernetes之Ingress和Ingress Controller 概念 通常情况下,service和pod的IP仅可在集群内部

12、kubernetes之ingress及Ingress Controller

一.概念 ClusterIP:例如svc所分配的ip地址 NodePort:k8s集群物理机机通信地址,client --> NodeIP:NodePort --> ClusterIP:ServicePort --> PodIP:containerPort No ClusterIP:Headless Service ,ServiceName --> PodIP Ingress:负责7层调度 二.ingress-nginx部署 # cat mandatory.yaml apiVers

[系统集成] 用 Kubernetes Nginx Ingress 实现 HTTP 服务发布与负载均衡

用户在 Kubernetes 上部署的服务一般运行于私有网络,Pod和Service 提供了 hostPort,NodePort等参数用于暴露这些服务端口到K8S节点上,供使用者访问.这样的方法有明显缺点: 1)容易占用过多的主机端口: 2)服务端口暴露到多台主机会增加防火墙和安全配置的难度 3)默认的hostPort,NodePort方式没有负载均衡的作用 K8S的 Ingress 资源提供了另一种服务暴露的方法,它可以获取各个服务的状态,传递给nginx等工具进行配置修改.重新加载等工作,实

Kubernetes 使用 ingress 配置 https 集群(十五)

目录 一.背景 1.1 需求 1.2 Ingress 1.3 环境介绍 二.安装部署 2.1.创建后端 Pod 应用 2.2 创建后端 Pod Service 2.3.创建 ingress 资源 2.4.为 Nginx Pod 创建 Service 三.升级为 https 3.1 首先我们要制作证书 3.2.创建 secret 资源 3.3 更改 ingress 资源 3.4 浏览器访问验证 四.ingress 资源介绍 4.1.通过访问路径过滤 4.2.基于名称解析的虚拟主机 4.3.http

kubernetes 学习 ingress

1:查看ingress kubectl get ing -n default 2:   编辑ingress,而后会自动重启.         kubectl edit ing  XXXXXXXXX    3:    查看pod  kubectl get pods -n namespace 4:    查看log kubectl logs -f pod_name  -n namespace 原文地址:https://www.cnblogs.com/liufei1983/p/9280746.html

kubernetes的Ingress资源介绍

Ingress 的资源帮助信息介绍 [[email protected] ~]# kubectl explain ingress KIND: Ingress VERSION: extensions/v1beta1 DESCRIPTION: Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend. An Ingress can be con