“Kubernetes ingress基础”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
 
(未显示同一用户的19个中间版本)
第20行: 第20行:
  
 
[https://www.cnblogs.com/syushin/p/15271304.html 使用Helm3.6 安装 Ingress-nginx ]
 
[https://www.cnblogs.com/syushin/p/15271304.html 使用Helm3.6 安装 Ingress-nginx ]
 +
 +
== install 2024==
 +
<pre>
 +
#images 换成自己在vps 推到自己的ali
 +
1.直接下载我已替换镜像地址 https://github.com/evan886/k8s-install/blob/main/deploy-v1.11.2.yaml
 +
 +
registry.cn-hangzhou.aliyuncs.com/evan886/my_k8s_containers:controllerv1.11.2
 +
registry.cn-hangzhou.aliyuncs.com/evan886/my_k8s_containers:kube-webhook-certgenv1.4.3
 +
 +
</pre>
  
 
==install(现在用kuboard 2022)==
 
==install(现在用kuboard 2022)==
 
===部署Ingress 控制器===
 
===部署Ingress 控制器===
 
https://kubernetes.github.io/ingress-nginx/deploy/
 
https://kubernetes.github.io/ingress-nginx/deploy/
 +
 +
[https://www.cnblogs.com/yinzhengjie/p/17975829 Ingress-Nginx使用指南上篇]
 
<pre>
 
<pre>
  
#2022
+
#2022 ok
root@k8s-master:~# kubectl apply -f  deploy.yaml
+
首先,需要匹配Ingress-nginx版本和kubernetes版本。 在https://github.com/kubernetes/ingress-nginx可以找到
namespace/ingress-nginx created
+
Supported Versions table
serviceaccount/ingress-nginx created
 
serviceaccount/ingress-nginx-admission created
 
role.rbac.authorization.k8s.io/ingress-nginx created
 
role.rbac.authorization.k8s.io/ingress-nginx-admission created
 
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
 
clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created
 
rolebinding.rbac.authorization.k8s.io/ingress-nginx created
 
rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
 
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created
 
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
 
configmap/ingress-nginx-controller created
 
service/ingress-nginx-controller created
 
service/ingress-nginx-controller-admission created
 
deployment.apps/ingress-nginx-controller created
 
job.batch/ingress-nginx-admission-create created
 
job.batch/ingress-nginx-admission-patch created
 
ingressclass.networking.k8s.io/nginx created
 
validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created
 
root@k8s-master:~# kubectl create deployment demo --image=httpd --port=80
 
deployment.apps/demo created
 
root@k8s-master:~# kubectl expose deployment demo
 
service/demo exposed
 
root@k8s-master:~#  kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx --watch
 
NAMESPACE      NAME                                        READY  STATUS              RESTARTS  AGE
 
ingress-nginx  ingress-nginx-admission-create-5jc9p        0/1    ImagePullBackOff    0          2m47s
 
ingress-nginx  ingress-nginx-admission-patch-2mb45        0/1    ImagePullBackOff    0          2m47s
 
ingress-nginx  ingress-nginx-controller-55dcf56b68-gpckf  0/1    ContainerCreating  0          2m47s
 
ingress-nginx  ingress-nginx-admission-create-5jc9p        0/1    ErrImagePull        0          2m47s
 
ingress-nginx  ingress-nginx-admission-create-5jc9p        0/1    ImagePullBackOff    0          3m
 
  
  
 +
1.直接下载我已替换镜像地址 https://github.com/evan886/k8s-install/blob/main/deploy-v1.3.1.yaml
  
 +
2.官方 下载
 +
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.1/deploy/static/provider/cloud/deploy.yaml
  
#FQ吧 少年  以前的 2019年的
+
查看该文件用到了哪些镜像:
wget -c  https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
+
cat  deploy.yaml | grep  image  
 +
总之 registry.k8s.io 全换成https://dockerproxy.com 切记,不要替换少了
  
kubectl apply -f mandatory.yaml
+
https://dockerproxy.com/docs 真是好东西 感谢
  
namespace/ingress-nginx configured
+
添加内容 暴露controller  端口,不行可能 404 ,ln 496就是添加的内容
configmap/nginx-configuration unchanged
 
configmap/tcp-services created
 
configmap/udp-services created
 
serviceaccount/nginx-ingress-serviceaccount unchanged
 
clusterrole.rbac.authorization.k8s.io/nginx-ingress-clusterrole configured
 
role.rbac.authorization.k8s.io/nginx-ingress-role unchanged
 
rolebinding.rbac.authorization.k8s.io/nginx-ingress-role-nisa-binding unchanged
 
clusterrolebinding.rbac.authorization.k8s.io/nginx-ingress-clusterrole-nisa-binding unchanged
 
deployment.apps/nginx-ingress-controller configured
 
  
 +
494        kubernetes.io/os: linux
 +
495      serviceAccountName: ingress-nginx
 +
496      hostNetwork: true
  
Verify installation
+
optimize suggestion优化建议
To check if the ingress controller pods have started,
+
deploy.yaml中默认 controller副本为1  可以改大replicas 提升性能
  
kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx --watch
+
kubectl apply -f  deploy.yaml # or  deploy-v1.3.1.yaml
NAMESPACE      NAME                                        READY  STATUS            RESTARTS  AGE
 
ingress-nginx  nginx-ingress-controller-86449c74bb-rthhw  0/1     ImagePullBackOff  0          2m5s
 
  
kubectl get pods -n ingress-nginx -o wide --watch #也是查看
+
查看结果 :
 +
root@ubuntu-200470-1:~/ingress# kubectl get pods -n ingress-nginx -o wide
 +
NAME                                        READY  STATUS      RESTARTS  AGE  IP              NODE    NOMINATED NODE  READINESS GATES
 +
ingress-nginx-admission-create-dbgqr        0/1    Completed  0          83m  10.234.253.158  work2  <none>          <none>
 +
ingress-nginx-admission-patch-mnsq9        0/1    Completed  3          83m  10.234.11.241    work1  <none>          <none>
 +
ingress-nginx-controller-5dc549b98b-6nnsh  1/1    Running    0          83m  192.168.10.82    work1  <none>          <none>
 +
root@ubuntu-200470-1:~/ingress#  
  
 +
root@ubuntu-200470-1:~/ingress# curl 192.168.10.82
 +
<html>
 +
<head><title>404 Not Found</title></head>
 +
<body>
 +
<center><h1>404 Not Found</h1></center>
 +
<hr><center>nginx</center>
 +
</body>
 +
</html
 +
成功
  
Once the operator pods are running, you can cancel the above command by typing Ctrl+C.
 
  
可见上面还不是runing  过一阵才好
+
nuc k8s
 +
root@ubuntu-200430-1:~/ingress# kubectl get pods -n ingress-nginx -o wide
 +
NAME                                        READY  STATUS      RESTARTS  AGE  IP              NODE    NOMINATED NODE  READINESS GATES
 +
ingress-nginx-admission-create-c87dq        0/1    Completed  0          50s  10.234.10.73    work1  <none>          <none>
 +
ingress-nginx-admission-patch-7jwbn        0/1    Completed  0          50s  10.234.228.242  work3  <none>          <none>
 +
ingress-nginx-controller-5dc549b98b-927zt  0/1    Running    0          50s  192.168.10.34    work3  <none>          <none>
  
kubectl get pods -n ingress-nginx
 
NAME                                        READY  STATUS    RESTARTS  AGE
 
nginx-ingress-controller-86449c74bb-rthhw  1/1    Running  0          19h
 
  
 
</pre>
 
</pre>
第101行: 第96行:
 
===部署svc===
 
===部署svc===
 
<pre>
 
<pre>
 +
#2024不用独立安装这个了
 
  kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
 
  kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
 
service/ingress-nginx created
 
service/ingress-nginx created
第111行: 第107行:
 
</pre>
 
</pre>
  
=trouble=
+
=usage=
<pre> kubectl get ing #ADDRESS 为空
+
== 最简单的使用例子==
NAME    HOSTS   ADDRESS   PORTS   AGE
+
=== run===
simple   *                80      4s
+
<pre>
 +
 
 +
##前提是已安装 ingress controller --  Ingress-Nginx
 +
kubectl apply -f apple-deployment-and-service.yaml
 +
 
 +
kubectl apply -f banana-deployment-and-service.yaml
 +
kubectl apply -f ingress.yaml
 +
 
 +
</pre>
 +
=== files===
 +
<pre>
 +
cat /root/apple-deployment-and-service.yaml
 +
kind: Deployment
 +
apiVersion: apps/v1
 +
metadata:
 +
  name: apple
 +
spec:
 +
  selector:
 +
    matchLabels:
 +
      app: apple
 +
  replicas: 2
 +
  template:
 +
    metadata:
 +
      labels:
 +
        app: apple
 +
    spec:
 +
      containers:
 +
        - name: apple
 +
          image: jxlwqq/http-echo
 +
          args:
 +
            - "--text=apple"
 +
          ports:
 +
            - containerPort: 8080
 +
 
 +
---
 +
 
 +
kind: Service
 +
apiVersion: v1
 +
metadata:
 +
  name: apple-svc
 +
spec:
 +
  selector:
 +
    app: apple
 +
  ports:
 +
    - port: 8080
 +
      targetPort: 8080
 +
 
 +
 
 +
cat /root/banana-deployment-and-service.yaml
 +
kind: Deployment
 +
apiVersion: apps/v1
 +
metadata:
 +
  name: banana
 +
spec:
 +
  selector:
 +
    matchLabels:
 +
      app: banana
 +
  replicas: 2
 +
  template:
 +
    metadata:
 +
      labels:
 +
        app: banana
 +
    spec:
 +
      containers:
 +
        - name: banana
 +
          image: jxlwqq/http-echo
 +
          args:
 +
            - "--text=banana"
 +
          ports:
 +
            - containerPort: 8080
 +
 
 +
---
 +
 
 +
kind: Service
 +
apiVersion: v1
 +
metadata:
 +
  name: banana-svc
 +
spec:
 +
  selector:
 +
    app: banana
 +
  ports:
 +
    - port: 8080
 +
      targetPort: 8080
 +
 
 +
cat /root/ingress.yml
 +
apiVersion: networking.k8s.io/v1
 +
kind: Ingress
 +
metadata:
 +
  name: fruit-ing
 +
  annotations:
 +
    nginx.ingress.kubernetes.io/rewrite-target: /
 +
 
 +
spec:
 +
  rules:
 +
    - host:  aa.com
 +
      http:
 +
        paths:
 +
          - path: /apple
 +
            pathType: Prefix
 +
            backend:
 +
              service:
 +
                name: apple-svc
 +
                port:
 +
                  number: 8080
 +
          - path: /banana
 +
            pathType: Prefix
 +
            backend:
 +
              service:
 +
                name: banana-svc
 +
                port:
 +
                  number: 8080
 +
  ingressClassName: nginx
 +
 
 +
</pre>
 +
=== test===
 +
<pre>
 +
kubectl get pod -n ingress-nginx  -o wide
 +
NAME                                       READY  STATUS      RESTARTS  AGE  IP              NODE    NOMINATED NODE  READINESS GATES
 +
ingress-nginx-admission-create-dbgqr        0/1    Completed  0          28m  10.234.253.158  work2  <none>          <none>
 +
ingress-nginx-admission-patch-mnsq9        0/1     Completed   3          28m   10.234.11.241    work1   <none>          <none>
 +
ingress-nginx-controller-5dc549b98b-6nnsh   1/1    Running    0          28m  192.168.10.82    work1  <none>          <none>
 +
 
 +
得知 ingress-nginx-controller 在节点2机器上ip  为192.168.10.82
 +
 
 +
cat /etc/hosts  | grep  aa.com
 +
192.168.10.82 aa.com
 +
➜  ~
 +
 
 
</pre>
 
</pre>
  
=usage=
+
== 简单的使用例子 old==
== 最简单的使用例子==
+
 
 
===** 创建一个空间 ===
 
===** 创建一个空间 ===
 
<pre>
 
<pre>
第223行: 第346行:
  
 
=see also=
 
=see also=
 +
[[K8s部署tomcat mysql 与ingress暴露服务]]
 +
 +
=references=
 +
 +
https://zhuanlan.zhihu.com/p/644289145
 +
 +
 +
 +
[https://blog.csdn.net/Azj12345/article/details/118862247  k8s集群中部署tomcat,访问方式使用Ingress,高可用 和NodePort方式]
  
 
[https://kubernetes.github.io/ingress-nginx/deploy/ 官方文档]
 
[https://kubernetes.github.io/ingress-nginx/deploy/ 官方文档]
第228行: 第360行:
 
[https://blog.csdn.net/java_zyq/article/details/82179107 从零开始搭建K8S--搭建K8S Ingress]
 
[https://blog.csdn.net/java_zyq/article/details/82179107 从零开始搭建K8S--搭建K8S Ingress]
  
 +
 +
[https://www.jianshu.com/p/1ef0bb822fcc Nginx Ingress TCP代理实现]
  
 
[https://www.cnblogs.com/evescn/p/12484975.html k8s ingress及ingress controller]
 
[https://www.cnblogs.com/evescn/p/12484975.html k8s ingress及ingress controller]

2024年10月9日 (三) 14:55的最新版本

Nginx ingress 使用ConfigMap来管理Nginx配置,nginx是大家熟知的代理和负载均衡软件,比起Traefik来说功能更加强大.

ngress是Kubernetes集群对外暴露服务的一种推荐方法,Ingress封装了nginx,背后还是nginx在发挥作用,Ingress的作用是不断检测pod的IP变化,然后将变化更新到nginx的配置中。从而当集群中有pod重启时,可以做到不用重启nginx

with Helm

#use helm  正常情况下如次  要FQ

helm upgrade --install ingress-nginx ingress-nginx \
  --repo https://kubernetes.github.io/ingress-nginx \
  --namespace ingress-nginx --create-namespace

Release "ingress-nginx" does not exist. Installing it now.

Error: failed to download "https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-4.1.4/ingress-nginx-4.1.4.tgz"

使用Helm3.6 安装 Ingress-nginx

install 2024

#images 换成自己在vps 推到自己的ali 
1.直接下载我已替换镜像地址 https://github.com/evan886/k8s-install/blob/main/deploy-v1.11.2.yaml

registry.cn-hangzhou.aliyuncs.com/evan886/my_k8s_containers:controllerv1.11.2
registry.cn-hangzhou.aliyuncs.com/evan886/my_k8s_containers:kube-webhook-certgenv1.4.3

install(现在用kuboard 2022)

部署Ingress 控制器

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

Ingress-Nginx使用指南上篇


#2022 ok
首先,需要匹配Ingress-nginx版本和kubernetes版本。 在https://github.com/kubernetes/ingress-nginx可以找到
Supported Versions table


1.直接下载我已替换镜像地址 https://github.com/evan886/k8s-install/blob/main/deploy-v1.3.1.yaml

2.官方 下载 
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.1/deploy/static/provider/cloud/deploy.yaml

查看该文件用到了哪些镜像:
 cat  deploy.yaml | grep  image  
总之 registry.k8s.io 全换成https://dockerproxy.com  切记,不要替换少了 

https://dockerproxy.com/docs 真是好东西 感谢

添加内容 暴露controller  端口,不行可能 404 ,ln 496就是添加的内容 

494         kubernetes.io/os: linux
495       serviceAccountName: ingress-nginx
496       hostNetwork: true

optimize suggestion优化建议
deploy.yaml中默认 controller副本为1  可以改大replicas 提升性能

kubectl apply -f  deploy.yaml # or  deploy-v1.3.1.yaml

查看结果 :
root@ubuntu-200470-1:~/ingress# kubectl get pods -n ingress-nginx -o wide
NAME                                        READY   STATUS      RESTARTS   AGE   IP               NODE    NOMINATED NODE   READINESS GATES
ingress-nginx-admission-create-dbgqr        0/1     Completed   0          83m   10.234.253.158   work2   <none>           <none>
ingress-nginx-admission-patch-mnsq9         0/1     Completed   3          83m   10.234.11.241    work1   <none>           <none>
ingress-nginx-controller-5dc549b98b-6nnsh   1/1     Running     0          83m   192.168.10.82    work1   <none>           <none>
root@ubuntu-200470-1:~/ingress# 

root@ubuntu-200470-1:~/ingress# curl 192.168.10.82
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html
成功 


nuc k8s 
root@ubuntu-200430-1:~/ingress# kubectl get pods -n ingress-nginx -o wide
NAME                                        READY   STATUS      RESTARTS   AGE   IP               NODE    NOMINATED NODE   READINESS GATES
ingress-nginx-admission-create-c87dq        0/1     Completed   0          50s   10.234.10.73     work1   <none>           <none>
ingress-nginx-admission-patch-7jwbn         0/1     Completed   0          50s   10.234.228.242   work3   <none>           <none>
ingress-nginx-controller-5dc549b98b-927zt   0/1     Running     0          50s   192.168.10.34    work3   <none>           <none>


部署svc

#2024不用独立安装这个了 
 kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
service/ingress-nginx created


[root@master ingress]# kubectl get svc -n ingress-nginx
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx   LoadBalancer   10.99.141.156   <pending>     80:31279/TCP,443:30847/TCP   2m43s

usage

最简单的使用例子

run


##前提是已安装 ingress controller --  Ingress-Nginx
kubectl apply -f apple-deployment-and-service.yaml

kubectl apply -f banana-deployment-and-service.yaml
kubectl apply -f ingress.yaml

files

cat /root/apple-deployment-and-service.yaml 
kind: Deployment
apiVersion: apps/v1
metadata:
  name: apple
spec:
  selector:
    matchLabels:
      app: apple
  replicas: 2
  template:
    metadata:
      labels:
        app: apple
    spec:
      containers:
        - name: apple
          image: jxlwqq/http-echo
          args:
            - "--text=apple"
          ports:
            - containerPort: 8080

---

kind: Service
apiVersion: v1
metadata:
  name: apple-svc
spec:
  selector:
    app: apple
  ports:
    - port: 8080
      targetPort: 8080


cat /root/banana-deployment-and-service.yaml 
kind: Deployment
apiVersion: apps/v1
metadata:
  name: banana
spec:
  selector:
    matchLabels:
      app: banana
  replicas: 2
  template:
    metadata:
      labels:
        app: banana
    spec:
      containers:
        - name: banana
          image: jxlwqq/http-echo
          args:
            - "--text=banana"
          ports:
            - containerPort: 8080

---

kind: Service
apiVersion: v1
metadata:
  name: banana-svc
spec:
  selector:
    app: banana
  ports:
    - port: 8080
      targetPort: 8080

 cat /root/ingress.yml 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: fruit-ing
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /

spec:
  rules:
    - host:  aa.com
      http:
        paths:
          - path: /apple
            pathType: Prefix
            backend:
              service:
                name: apple-svc
                port:
                  number: 8080
          - path: /banana
            pathType: Prefix
            backend:
              service:
                name: banana-svc
                port:
                  number: 8080
  ingressClassName: nginx

test

kubectl get pod -n ingress-nginx  -o wide 
NAME                                        READY   STATUS      RESTARTS   AGE   IP               NODE    NOMINATED NODE   READINESS GATES
ingress-nginx-admission-create-dbgqr        0/1     Completed   0          28m   10.234.253.158   work2   <none>           <none>
ingress-nginx-admission-patch-mnsq9         0/1     Completed   3          28m   10.234.11.241    work1   <none>           <none>
ingress-nginx-controller-5dc549b98b-6nnsh   1/1     Running     0          28m   192.168.10.82    work1   <none>           <none>

得知 ingress-nginx-controller 在节点2机器上ip  为192.168.10.82

 cat /etc/hosts  | grep  aa.com 
192.168.10.82 aa.com
➜  ~ 

简单的使用例子 old

** 创建一个空间


 cat  testing-namespace.yaml 
kind: Namespace
apiVersion: v1
metadata:
  name: testing
  labels:
    env: testing

** 创建 tomcat-deploy


cat  tomcat-deploy.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deploy
  namespace: testing
spec:
  replicas: 2
  selector:
    matchLabels:
      app: tomcat
  template:
    metadata:
      labels:
        app: tomcat
    spec:
      containers:
      - name: tomcat
        image: tomcat:8.0.50-jre8-alpine
        ports:
        - containerPort: 8080
          name: httpport
        - containerPort: 8009
          name: ajpport



** 创建 tomcat svc

          


 cat  tomcat-svc.yaml 
apiVersion: v1
kind: Service
metadata:
  name: tomcat-svc
  namespace: testing
  labels:
    app: tomcat-svc
spec:
  selector:
    app: tomcat
  ports:
  - name: httpport
    port: 80
    targetPort: 8080
    protocol: TCP


** 创建 tomcat-ingress


#前提 先在 kuboard 先创建个ingress 叫 tt

 cat tomcat-ingress.yaml 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: tomcat
  namespace: testing
  annotations:
    kubernetes.io/ingress.class: "tt"
    #kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: tt.com
  #- host: tomcat.ikubernetes.io
    http:
      paths:
      - path: 
        backend:
          serviceName: tomcat-svc
          servicePort: 80

** visa

host master ip http://tt.com:32136/

ingress https

see also

K8s部署tomcat mysql 与ingress暴露服务

references

https://zhuanlan.zhihu.com/p/644289145


k8s集群中部署tomcat,访问方式使用Ingress,高可用 和NodePort方式

官方文档

从零开始搭建K8S--搭建K8S Ingress


Nginx Ingress TCP代理实现

k8s ingress及ingress controller

aliyun Ingress 支持

aliyun通过界面创建路由(Ingress)

K8S 部署 ingress-nginx (一) 原理及搭建

k8s安装traefik作为ingress


通过helm Nginx ingress安装

解决kubernetes中ingress-nginx配置问题

Kubernetes - nginx-ingress 配置跳坑指南

为什么我不使用Kubernetes的Ingress


kubernetes中服务的暴露访问方式kubernetes ingress使用


搭建K8S Ingress安装部分已老