首页 > 系统相关 >kubernetes安装ingress-nginx的步骤

kubernetes安装ingress-nginx的步骤

时间:2023-01-15 12:05:11浏览次数:64  
标签:ingress name kubernetes yaml nginx csctbb


kubernetes安装ingress-nginx的步骤

系统版本:CentOs8.1
k8s版本:v1.21.3
containerd版本:ctr containerd.io 1.4.3

一: 准备yaml文件

github仓库地址:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
以前用如上的地址下载,现在好像是不灵了

那我们选择ingress-nginx 0.20.0版本 https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0

下载 service-nodeport.yaml
​​​ https://github.com/kubernetes/ingress-nginx/blob/nginx-0.20.0/deploy/provider/baremetal/service-nodeport.yaml​

下载 mandatory.yaml
​​​ https://github.com/kubernetes/ingress-nginx/blob/nginx-0.20.0/deploy/mandatory.yaml​

将镜像地址替换为阿里可下载的地址(略)

#修改service-nodeport.yaml
vim service-nodeport.yaml

apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
nodePort: 32080 #http这里修改
- name: https
port: 443
targetPort: 443
protocol: TCP
nodePort: 32443 #https这里修改
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx

部署
kubectl create namespace ingress-nginx
kubectl apply -f mandatory.yaml
kubectl apply -f service-nodeport.yaml

执行mandatory.yaml有异常报错

error: unable to recognize “mandatory.yaml”: no matches for kind “Deployment” in version “extensions/v1beta1”

解决方法, 修改mandatory.yarml文件
将apiVersion: extensions/v1beta1 修改成 apiVersion: apps/v1
再次执行
kubectl apply -f mandatory.yaml

正常

访问nodeport看看是否有返回信息
​​​ http://192.168.43.152:32080/​

kubernetes安装ingress-nginx的步骤_github


测试阶段

配置个服务

[root@ck8s1 ingress]# cat ingress-deploy-demon.yaml 
apiVersion: v1
kind: Service
metadata:
name: csctbb
namespace: default
spec:
selector:
app: csctbb
release: canary
ports:
- name: http
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: csctbb-deploy
spec:
replicas: 5
selector:
matchLabels:
app: csctbb
release: canary
template:
metadata:
labels:
app: csctbb
release: canary
spec:
containers:
- name: csctbb
image: ikubernetes/myapp:v2
ports:
- name: httpd
containerPort: 80

配置ingress

[root@ck8s1 ingress]# cat ingress-test.yaml 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-csctbb
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: csctbb.csctbb.com
http:
paths:
- path:
backend:
serviceName: csctbb
servicePort: 80

部署服务

[root@ck8s1 ingress]# kubectl apply -f ingress-deploy-demon.yaml 
service/csctbb created
deployment.apps/csctbb-deploy created
[root@ck8s1 ingress]# kubectl apply -f ingress-test.yaml
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.extensions/ingress-csctbb created

查看ingress
[root@ck8s1 ingress]# kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-csctbb csctbb.csctbb.com 80 22s

配置host访问
192.168.43.1 csctbb.csctbb.com

完成 !


标签:ingress,name,kubernetes,yaml,nginx,csctbb
From: https://blog.51cto.com/u_15941303/6008509

相关文章

  • 为什么推荐大家使用 Nginx 而不是 Apache?
    无论是Nginx还是Apache都是Web服务器应用,通俗点说我们的网站都是需要Web服务器应用来展现给客户的,而服务器是供Web服务器应用正常稳定的运行的基础。所以说选择好......
  • nginx内置参数
    $args#请求中的参数值$query_string#同$args$arg_NAME#GET请求中NAME的值$is_args#如果请求中有......
  • Kubernetes:通过轻量化工具 kubespy 实时观察YAML资源变更
    写在前面分享一个小工具​​kubespy​​给小伙伴博文内容涉及:工具的简单介绍下载安装以​​kubectl​​插件方式使用Demo理解不足小伙伴帮忙指正我所渴求的,無非是......
  • nginx 统计UV PV IP等
    cat/var/log/nginx/access.log1.根据访问IP统计UVawk'{print$1}' /var/log/nginx/access.log|sort|uniq-c|wc-l2.统计访问URL统计PVawk'{print$7}'/var/log/ng......
  • windows下快速安装nginx并配置开机自启动的方法
    目录一、windows系统下Nginx安装启动流程:二、设置Nginx开机自动启动1、自启动工具下载2、自启动工具安装3、把nginx加入到windows服务中nginx已经是我们日常开发中在常用不......
  • vite2.9 + vue3.2 打包部署到nginx上刷新页面404问题
    vite2.9+vue3.2打包部署到nginx上刷新页面404问题在本地运行没问题,部署到服务器上,能正常访问,但是刷新之后页面404原有的Nginx配置为:server{listen......
  • nginx+vite 项目打包及部署
    项目打包及部署到服务器二级路由例如:我希望将打包的项目部署到http://localhost:8088/web/上一.项目配置及打包项目部署到服务器二级路由需要配置基础路径base,即需要......
  • nginx rewrite 跨域
    1.rewrite指令rewrite指令语法:rewriteregexreplacement[flag];作用域:server、location、if功能:如果一个URI匹配指定的正则表达式regex,URI就按照replacement重写。r......
  • Dockerfile文件详解和nginx镜像制作示例
    Dockerfile文件中各个常用的基本命令,共18个指令FROMMAINTAINERRUNCMDLABELEXPOSEENVADDCOPYENTRYPOINTVOLUMEUSERSHELLWORKDIRONBUILDSTOPSIGNALHEALTHCH......
  • kubernetes v1.24.0安装ingress
    环境kubernetesv1.24.0ingress:controller:v1.1.2Ingress-nginx官网https://kubernetes.github.io/ingress-nginx/获取deploy.yaml文件kubectlapply-fhttps://r......