首页 > 系统相关 >采用Ingress暴露容器化应用(Nginx)

采用Ingress暴露容器化应用(Nginx)

时间:2022-10-17 18:47:44浏览次数:50  
标签:容器 Ingress nginx admission ingress Nginx k8smaster k8s root

1.部署容器化应用

[root@k8smaster ~]# kubectl create deployment nginx --image=nginx
deployment.apps/nginx created

2.暴露该服务

[root@k8smaster ~]# kubectl expose deployment nginx --port=80 --target-port=80 --type=NodePort
service/nginx exposed
[root@k8smaster ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 47h
nginx NodePort 10.107.162.17 <none> 80:32159/TCP 34s
springboot-k8s NodePort 10.104.165.244 <none> 8080:31129/TCP 6h24m
tomcat NodePort 10.108.243.100 <none> 8080:31891/TCP 32h

 

3.部署ingress inginx

 

[root@k8smaster ~]# kubectl apply -f ingress-deploy.yaml
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
configmap/ingress-nginx-controller created
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created
role.rbac.authorization.k8s.io/ingress-nginx created
rolebinding.rbac.authorization.k8s.io/ingress-nginx created
service/ingress-nginx-controller-admission created
service/ingress-nginx-controller created
deployment.apps/ingress-nginx-controller created
validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created
serviceaccount/ingress-nginx-admission created
clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
role.rbac.authorization.k8s.io/ingress-nginx-admission created
rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
job.batch/ingress-nginx-admission-create created
job.batch/ingress-nginx-admission-patch created
[root@k8smaster ~]#

 

4.查看ingress状态

[root@k8smaster ~]# kubectl get service -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.99.29.48 <none> 80:31771/TCP,443:32731/TCP 59s
ingress-nginx-controller-admission ClusterIP 10.98.171.141 <none> 443/TCP 59s
[root@k8smaster ~]# kubectl get deploy -n ingress-nginx
NAME READY UP-TO-DATE AVAILABLE AGE
ingress-nginx-controller 0/1 1 0 77s
[root@k8smaster ~]# kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-p6xhl 0/1 Completed 0 92s
ingress-nginx-admission-patch-lxm5j 0/1 Completed 3 92s
ingress-nginx-controller-668848df7f-kw62q 0/1 Running 0 92s

 

5.创建ingress规则

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: k8s-ingress
spec:
  rules:
  - host: www.abc.com
    http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: nginx
            port: 
              number: 80

 

[root@k8smaster ~]#
[root@k8smaster ~]# kubectl apply -f ingress-nginx-rule.yaml
ingress.networking.k8s.io/k8s-ingress created
[root@k8smaster ~]#

6.查规则
[root@k8smaster ~]# kubectl get ing
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
k8s-ingress <none> www.abc.com 192.168.1.201 80 73s
[root@k8smaster ~]#

 

访问:http://192.168.1.201/

或者电脑C:\Windows\System32\drivers\etc  修改hosts  加上192.168.1.201 www.abc.com     然后浏览器访问www.abc.com

 

标签:容器,Ingress,nginx,admission,ingress,Nginx,k8smaster,k8s,root
From: https://www.cnblogs.com/yitian395/p/16800198.html

相关文章

  • Docker 容器使用
      Docker客户端使用Linux最好还是整个服务器,买太贵了,建议租一个,我用的是3A服务器,大家一起来学习吧!docker 客户端非常简单 ,我们可以直接输入 docker 命令来......
  • Docker容器简介及命令
    使用Linux最好还是整个服务器,买太贵了,建议租一个,我用的是3A服务器docker简述Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像......
  • lua_nginx_module 简单解读
       最近写的文章比较少一些,一方面是因为自己最近疏忽了,还有一部分原因是自己在阅读luanginxmodule源码,相关资料较少,自己又并无lua及c基础,需要临时学习的东西较......
  • mac系统下用nginx服务器部署页面
    1.安装nginx(需要先安装Homebrew)。使用命令brewinstallnginx安装nginx。 2.用命令open/usr/local/Cellar/nginx用访达打开安装路径。 3.打开bin文件夹,双击nginx文件,启动......
  • NGINX配置文件,REWRITE,IF
    NGINX配置文件,REWRITE,IF目录NGINX配置文件,REWRITE,IFREWRITIF基于浏览器实现分离案例防盗链案例nginx配置文件,rewrite,if[rewrit]if[基于浏览器实现分离案例][防盗......
  • 【Nginx1.12.2安装步骤】
    前言最近利用时间来进行学习,之前进行过Nginx的入门学习,本篇博客主要记录一下安装Nginx的过程,以便为以后的工作奠定基础.核心步骤一安装gcc环境:yuminstallgcc-c++安装p......
  • nginx配置文件rewrite和if
    nginx配置文件rewrite和ifrewrite语法:rewriteregexreplacementflag;,如:rewrite^/images/(.*\.jpg)$/imgs/$1break;此处的$1用于引用(.*.jpg)匹配到的内容,又如:re......
  • nginx入门到实战
    第一节、安装升级1.1、linux初始化1、关闭防火墙systemctlstopfirewalldsystemctldisablefirewalld2、关闭selinuxvim/etc/selinux/configSELINUX=disabled......
  • Docker容器底层技术
    前戏为了更好地理解容器的特性,可以刨析容器的底层实现技术。​​cgroup​​​和​​namespace​​是最重要的两种技术。cgroup实现资源限额,namespace实现资源隔离。 cgroup......
  • 配置容器应用Secret
    Secret资源的功能类似于ConfigMap,但它专用于存放敏感数据,例如密码、数字证书、私钥、令牌和SSHkey等,而不需要把这些敏感数据暴露到镜像或者PodSpec中。Secret可以以V......