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

k8s 配置ingress 并做一个demo

需求:

  • k8s 配置好之后除了 nodeport 以外都是对集群内部的行为

  • 使用nodeport 并不是很友好,要自己处理很多的端口管理

  • 使用ingress 可以更好的整合配置服务

进程:

  • 下载ingress-nginx 的yaml 文件

https://github.com/kubernetes/ingress-nginx/blob/nginx-0.30.0/deploy/static/mandatory.yaml
  • 安装

kubectl create -f mandatory.yaml
  • 安装的时候会有一些warning 影响不大

  • 查看 ingress-nignx 的配置启动情况

kubectl get all -n ingress-nginx
  • 如果controller 没有ready 需要找一下原因

  • 查看 这个pod 的状态

kubectl get pod -n ingress-nginx --show-labels
  • 果然是有问题了,controller 状态是crash查看pod 的状态信息简介

kubectl describe pod nginx-ingress-controller-54b86f8f7b-bk8s4  -n ingress-nginx
  • 查看pod 的启动日志

kubectl logs nginx-ingress-controller-54b86f8f7b-bk8s4 -n ingress-nginx
  • 看起来是网络不通畅

  • 修改下载下来的mandatory.yaml 在第214 行加上 hostNetwork: true 重新执行apply 可执行文件在最下方

  • 做一个端口输入service

apiVersion: v1
kind: Service
metadata:name: ingress-nginx-svcnamespace: ingress-nginx #和controller 保持一致
spec:type: NodePort #必须是这个ports:- name: httpport: 80targetPort: 80protocol: TCPnodePort: 32080  #http 80 映射到32080- name: httpsport: 443targetPort: 443protocol: TCPnodePort: 32443  #https 443 映射到底32443selector: #内容参考controller 的metadataapp.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx
  • apply 之后查看网址内容

  • 404 表示能连通,但是没有服务 ingress 安装完成

进程2:

  • 安装完成之后做一个测验

  • 配置一个可启动的服务 deployment 和 service 的配置信息不明白的可以看k8s pod deployment service ingress 关系

apiVersion: apps/v1
kind: Deployment
metadata:name: myappnamespace: default
spec:replicas: 1selector:matchLabels:app: myapptemplate:metadata:namespace: defaultlabels:app: myappspec:containers:- name: myappimage: ikubernetes/myapp:v1---
apiVersion: v1
kind: Service
metadata:name: myappnamespace: default
spec:selector:app: myappports:- name: httpport: 80targetPort: 80
  • 创建完成之后再创建一个ingress 来做反向代理

apiVersion: extensions/v1beta1
kind: Ingress
metadata:name: ingress-myappnamespace: defaultannotations:kubernetes.io/ingress.class: "nginx"
spec:rules:- host: www.firstdemo.comhttp:paths:- path: /backend:serviceName: myappservicePort: 80
  • apply 之后在要测试服务的机器上做一个端口映射

#hosts 文件
192.168.197.135 www.firstdemo.com
  • 打开网站www.firstdemo.com:32080 会看到一个已经启动了的服务

拓展:

  • mandatory.yaml

apiVersion: v1
kind: Namespace
metadata:name: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx---kind: ConfigMap
apiVersion: v1
metadata:name: nginx-configurationnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx---
kind: ConfigMap
apiVersion: v1
metadata:name: tcp-servicesnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx---
kind: ConfigMap
apiVersion: v1
metadata:name: udp-servicesnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx---
apiVersion: v1
kind: ServiceAccount
metadata:name: nginx-ingress-serviceaccountnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:name: nginx-ingress-clusterrolelabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
rules:- apiGroups:- ""resources:- configmaps- endpoints- nodes- pods- secretsverbs:- list- watch- apiGroups:- ""resources:- nodesverbs:- get- apiGroups:- ""resources:- servicesverbs:- get- list- watch- apiGroups:- ""resources:- eventsverbs:- create- patch- apiGroups:- "extensions"- "networking.k8s.io"resources:- ingressesverbs:- get- list- watch- apiGroups:- "extensions"- "networking.k8s.io"resources:- ingresses/statusverbs:- update---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:name: nginx-ingress-rolenamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
rules:- apiGroups:- ""resources:- configmaps- pods- secrets- namespacesverbs:- get- apiGroups:- ""resources:- configmapsresourceNames:# Defaults to "<election-id>-<ingress-class>"# Here: "<ingress-controller-leader>-<nginx>"# This has to be adapted if you change either parameter# when launching the nginx-ingress-controller.- "ingress-controller-leader-nginx"verbs:- get- update- apiGroups:- ""resources:- configmapsverbs:- create- apiGroups:- ""resources:- endpointsverbs:- get---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:name: nginx-ingress-role-nisa-bindingnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
roleRef:apiGroup: rbac.authorization.k8s.iokind: Rolename: nginx-ingress-role
subjects:- kind: ServiceAccountname: nginx-ingress-serviceaccountnamespace: ingress-nginx---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:name: nginx-ingress-clusterrole-nisa-bindinglabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: nginx-ingress-clusterrole
subjects:- kind: ServiceAccountname: nginx-ingress-serviceaccountnamespace: ingress-nginx---apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-ingress-controllernamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
spec:replicas: 1selector:matchLabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginxtemplate:metadata:labels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginxannotations:prometheus.io/port: "10254"prometheus.io/scrape: "true"spec:# wait up to five minutes for the drain of connectionshostNetwork: trueterminationGracePeriodSeconds: 300serviceAccountName: nginx-ingress-serviceaccountnodeSelector:kubernetes.io/os: linuxcontainers:- name: nginx-ingress-controllerimage: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0args:- /nginx-ingress-controller- --configmap=$(POD_NAMESPACE)/nginx-configuration- --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services- --udp-services-configmap=$(POD_NAMESPACE)/udp-services- --publish-service=$(POD_NAMESPACE)/ingress-nginx- --annotations-prefix=nginx.ingress.kubernetes.iosecurityContext:allowPrivilegeEscalation: truecapabilities:drop:- ALLadd:- NET_BIND_SERVICE# www-data -> 101runAsUser: 101env:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespaceports:- name: httpcontainerPort: 80protocol: TCP- name: httpscontainerPort: 443protocol: TCPlivenessProbe:failureThreshold: 3httpGet:path: /healthzport: 10254scheme: HTTPinitialDelaySeconds: 10periodSeconds: 10successThreshold: 1timeoutSeconds: 10readinessProbe:failureThreshold: 3httpGet:path: /healthzport: 10254scheme: HTTPperiodSeconds: 10successThreshold: 1timeoutSeconds: 10lifecycle:preStop:exec:command:- /wait-shutdown---apiVersion: v1
kind: LimitRange
metadata:name: ingress-nginxnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginx
spec:limits:- min:memory: 90Micpu: 100mtype: Container

相关文章:

k8s 配置ingress 并做一个demo

需求&#xff1a;k8s 配置好之后除了 nodeport 以外都是对集群内部的行为使用nodeport 并不是很友好&#xff0c;要自己处理很多的端口管理使用ingress 可以更好的整合配置服务进程&#xff1a;下载ingress-nginx 的yaml 文件https://github.com/kubernetes/ingress-nginx/blob…...

【手把手一起学习】(七) Altium Designer 20常用PCB设计规则

1 常用PCB设计规则 PCB规则设计是PCB设计中至关重要的环节&#xff0c;它约束了电气要求、布线方式、器件摆放位置等&#xff0c;为后续的手动布局、布线提供依据。完善的PCB规则设计&#xff0c;可以减少设计中的错误&#xff0c;提高PCB设计效率。 1.1 PCB设计规则管理器 …...

(01)Unity 中使用 HDRP

概述Unity在2019.2版本中推出HDRP&#xff08;高清渲染管线&#xff09;&#xff0c;目的是为了提高图形质量&#xff0c;实现从照片写实到风格化的图像。先看一下官方对HDRP的概述&#xff1a;高清渲染管线 &#xff08;HDRP&#xff09; 是由 Unity 构建的高保真脚本化渲染管…...

使用cmake在win10编译yolov5+tensorRT+cuda+cudnn+protobuf代码进行混合编译

这里进行之前需要把protobuf在win10下编译&#xff0c;可以参考这篇文章从Linux下载下来的工程代码&#xff0c;这里建议直接使用vs系列打开不要用vscode打开&#xff0c;vscode对win下的cmake不友好&#xff0c;主要体现在报错机制无法直接定位&#xff0c;题主的环境是vs2022…...

《C++ Primer Plus》第17章:输入、输出和文件(7)

编程练习 编写一个程序计算输入流中第一个$之前的字符数目&#xff0c;并将$留在输入流中。 #include<iostream>int main() {int ct 0;while(std::cin.peek()!$){ct;std::cin.get();}std::cout << "num: " << ct << std::endl;return 0; }答…...

PGLBox 超大规模 GPU 端对端图学习训练框架正式发布

作者 | PGLBox项目组 导读 PGLBox是百度研发的基于GPU的大规模图模型训练框架&#xff0c;支持数百亿节点和边的图模型全GPU训练&#xff0c;已在百度广泛部署。相比业界主流的分布式 CPU 解决方案&#xff0c;PGLBox 具有超高性能、超大规模、算法丰富、灵活易用、落地广泛等优…...

sql-labs-Less1

靶场搭建好了&#xff0c;访问题目路径 http://127.0.0.1/sqli-labs-master/Less-1/ 我最开始在做sql-labs靶场的时候很迷茫&#xff0c;不知道最后到底要得到些什么&#xff0c;而现在我很清楚&#xff0c;sql注入可以获取数据库中的信息&#xff0c;而获取信息就是我们的目标…...

又一个国内类ChatGPT模型?【秘塔科技上线自研LLM大模型「对话写作猫」】

又一个国内类ChatGPT模型&#xff1f;【秘塔科技上线自研LLM大模型「对话写作猫」】 说个题外话&#xff0c;今天一大早就收到了Biying的邮件。前段时间不是申请了New Biying的内测吗&#xff1f;下午可以尝试一下玩一会儿。如果体验感还不错或者还有很多bug&#xff0c;那我到…...

卷麻了,00后测试用例写的比我还好,简直无地自容......

经常看到无论是刚入职场的新人&#xff0c;还是工作了一段时间的老人&#xff0c;都会对编写测试用例感到困扰&#xff1f;例如&#xff1a; 如何编写测试用例&#xff1f; 作为一个测试新人&#xff0c;刚开始接触测试&#xff0c;对于怎么写测试用例很是头疼&#xff0c;无法…...

动态网页的核心——JSP

文章目录1&#xff0c;JSP 概述2&#xff0c;JSP 小案例2.1 搭建环境2.2 导入 JSP 依赖2.3 创建 jsp 页面2.4 编写代码2.5 测试3&#xff0c;JSP 原理4&#xff0c;JSP 总结4.1 JSP的 缺点4.2技术的发展历程4.3JSP的必要性最后说一句1&#xff0c;JSP 概述 JSP&#xff08;全称…...

RK3588平台开发系列讲解(系统篇)init.d介绍

平台内核版本安卓版本RK3588Linux 5.10Android 12文章目录 一、Linux启动简介二、sysvinit配置三、inid.d介绍沉淀、分享、成长,让自己和他人都能有所收获!😄 📢本篇介绍init.d相关知识。 一、Linux启动简介 Linux用户空间启动时,第一个会启动init进程,用来引导启动其…...

taobao.user.buyer.get( 查询买家信息API )

&#xffe5;开放平台基础API必须用户授权 查询买家信息API&#xff0c;只能买家类应用调用。 公共参数 请求地址: HTTP地址 http://gw.api.taobao.com/router/rest 公共请求参数: 公共响应参数: 请求参数 响应参数 点击获取key和secret 请求示例 TaobaoClient client new…...

python学生信息管理系统

wx供重浩&#xff1a;创享日记 对话框发送&#xff1a;python学生信息 免费获取完整源码源文件配置教程说明等 在IDLE中运行《学生信息管理系统》即可进入如图1所示的系统主界面。在该界面中可以选择要使用功能对应的菜单进行不同的操作。在选择功能菜单时&#xff0c;有两种方…...

【微信小程序】-- WXML 模板语法 - 条件渲染 -- wx:if hidden (十一)

&#x1f48c; 所属专栏&#xff1a;【微信小程序开发教程】 &#x1f600; 作  者&#xff1a;我是夜阑的狗&#x1f436; &#x1f680; 个人简介&#xff1a;一个正在努力学技术的CV工程师&#xff0c;专注基础和实战分享 &#xff0c;欢迎咨询&#xff01; &…...

2023上半年软考,广州/东莞/深圳/江苏报班是明智的选择

软考是全国计算机技术与软件专业技术资格&#xff08;水平&#xff09;考试&#xff08;简称软考&#xff09;项目&#xff0c;是由国家人力资源和社会保障部、工业和信息化部共同组织的国家级考试&#xff0c;既属于国家职业资格考试&#xff0c;又是职称资格考试。 系统集成…...

C++修炼之练气期一层——命名空间

目录 1.引例 2.命名空间的定义 3.命名空间的使用 4.命名空间使用注意事项 1.引例 #include <stdio.h> #include <stdlib.h>int rand 10;int main() {printf("%d\n", rand);return 0; } 当我们用C语言写下这样的代码&#xff0c;看着并没有什么语法…...

matplotlib综合学习

1.arange函数arange函数需要三个参数&#xff0c;分别为起始点、终止点、采样间隔。采样间隔默认值为1看例子&#xff1a; import numpy as np #import matplotlib.pyplot as plt xnp.arange(-5,5,1) print(x)2.绘制sin(x)曲线import numpy as np import matplotlib.pyplot as …...

IIS .Net Core 413错误和Request body too large解决办法

错误描述图片比较大时&#xff0c;在前端上传就报413错误。根本到不了后端。在网上看到这个文章比较有用。https://blog.csdn.net/wstever/article/details/1288707421、修改网站Web.config配置文件加入下面这段配置<?xmlversion"1.0" encoding"utf-8"…...

Spring Boot数据访问—(springboot 多数据源)—官方原版

Spring Boot 包含许多用于处理数据源的启动器&#xff0c;本文回答与执行此操作相关的问题。一、配置自定义数据源要配置自己的DataSource&#xff0c;请在配置中定义该类型的Bean。Spring Boot在任何需要的地方重用DataSource&#xff0c;包括数据库初始化。如果需要外部化某些…...

高燃!GitHub上标星75k+超牛的Java面试突击版

前言不论是校招还是社招都避免不了各种面试。笔试&#xff0c;如何去准备这些东西就显得格外重要。不论是笔试还是面试都是有章可循的&#xff0c;我这个有章可循‘说的意思只是说应对技术面试是可以提前准备。运筹帷幄之后&#xff0c;决胜千里之外!不打毫无准备的仗,我觉得大…...

Lombok 的 @Data 注解失效,未生成 getter/setter 方法引发的HTTP 406 错误

HTTP 状态码 406 (Not Acceptable) 和 500 (Internal Server Error) 是两类完全不同的错误&#xff0c;它们的含义、原因和解决方法都有显著区别。以下是详细对比&#xff1a; 1. HTTP 406 (Not Acceptable) 含义&#xff1a; 客户端请求的内容类型与服务器支持的内容类型不匹…...

【力扣数据库知识手册笔记】索引

索引 索引的优缺点 优点1. 通过创建唯一性索引&#xff0c;可以保证数据库表中每一行数据的唯一性。2. 可以加快数据的检索速度&#xff08;创建索引的主要原因&#xff09;。3. 可以加速表和表之间的连接&#xff0c;实现数据的参考完整性。4. 可以在查询过程中&#xff0c;…...

【大模型RAG】Docker 一键部署 Milvus 完整攻略

本文概要 Milvus 2.5 Stand-alone 版可通过 Docker 在几分钟内完成安装&#xff1b;只需暴露 19530&#xff08;gRPC&#xff09;与 9091&#xff08;HTTP/WebUI&#xff09;两个端口&#xff0c;即可让本地电脑通过 PyMilvus 或浏览器访问远程 Linux 服务器上的 Milvus。下面…...

高频面试之3Zookeeper

高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个&#xff1f;3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制&#xff08;过半机制&#xff0…...

如何在最短时间内提升打ctf(web)的水平?

刚刚刷完2遍 bugku 的 web 题&#xff0c;前来答题。 每个人对刷题理解是不同&#xff0c;有的人是看了writeup就等于刷了&#xff0c;有的人是收藏了writeup就等于刷了&#xff0c;有的人是跟着writeup做了一遍就等于刷了&#xff0c;还有的人是独立思考做了一遍就等于刷了。…...

Android 之 kotlin 语言学习笔记三(Kotlin-Java 互操作)

参考官方文档&#xff1a;https://developer.android.google.cn/kotlin/interop?hlzh-cn 一、Java&#xff08;供 Kotlin 使用&#xff09; 1、不得使用硬关键字 不要使用 Kotlin 的任何硬关键字作为方法的名称 或字段。允许使用 Kotlin 的软关键字、修饰符关键字和特殊标识…...

Aspose.PDF 限制绕过方案:Java 字节码技术实战分享(仅供学习)

Aspose.PDF 限制绕过方案&#xff1a;Java 字节码技术实战分享&#xff08;仅供学习&#xff09; 一、Aspose.PDF 简介二、说明&#xff08;⚠️仅供学习与研究使用&#xff09;三、技术流程总览四、准备工作1. 下载 Jar 包2. Maven 项目依赖配置 五、字节码修改实现代码&#…...

视觉slam十四讲实践部分记录——ch2、ch3

ch2 一、使用g++编译.cpp为可执行文件并运行(P30) g++ helloSLAM.cpp ./a.out运行 二、使用cmake编译 mkdir build cd build cmake .. makeCMakeCache.txt 文件仍然指向旧的目录。这表明在源代码目录中可能还存在旧的 CMakeCache.txt 文件,或者在构建过程中仍然引用了旧的路…...

STM32标准库-ADC数模转换器

文章目录 一、ADC1.1简介1. 2逐次逼近型ADC1.3ADC框图1.4ADC基本结构1.4.1 信号 “上车点”&#xff1a;输入模块&#xff08;GPIO、温度、V_REFINT&#xff09;1.4.2 信号 “调度站”&#xff1a;多路开关1.4.3 信号 “加工厂”&#xff1a;ADC 转换器&#xff08;规则组 注入…...

渗透实战PortSwigger Labs指南:自定义标签XSS和SVG XSS利用

阻止除自定义标签之外的所有标签 先输入一些标签测试&#xff0c;说是全部标签都被禁了 除了自定义的 自定义<my-tag onmouseoveralert(xss)> <my-tag idx onfocusalert(document.cookie) tabindex1> onfocus 当元素获得焦点时&#xff08;如通过点击或键盘导航&…...