In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the method of deploying ingress-nginx in K8s". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Deploy and configure Ingress
1. Get the configuration file
# File has been downloaded to the local https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0/deploy
2. Prepare for mirroring
Unzip ingress-nginx-nginx-0.20.0.zipcd ingress-nginx-nginx-0.20.0/deploy/vim mandatory.yaml # Collection of other files # Edit the mandatory.yaml file and change the defaultbackend image address to the image address of Ali Cloud (as shown below) image: registry.cn-hangzhou.aliyuncs.com/allinpay/defaultbackend-amd64:v1.5
3. Installation
Kubectl apply-f mandatory.yaml
# wait a moment and query kubectl get namespacekubectl get pods-n ingress-nginx using the following command
4. Create backend pod and service (pod-B, service-B)
Vim deploy-demo.yamlapiVersion: v1kind: Servicemetadata: name: myapp namespace: defaultspec: selector: app: myapp release: canary ports:-name: http targetPort: 80 port: 80 UV-apiVersion: apps/v1kind: Deploymentmetadata: name: myapp-deploy namespace: defaultspec: replicas: 3 selector: matchLabels: app: myapp release: canary template: metadata: labels: app: myapp release: canary spec: Containers:-name: myapp image: ikubernetes/myapp:v2 ports:-name: http containerPort: 8 applications configure kubectl apply-f deploy-demo.yaml# View kubectl get pods
5. Create service-A
Vim service-nodeport.yamlapiVersion: v1kind: Servicemetadata: name: ingress-nginx namespace: ingress-nginx labels: app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/ part-of: ingress-nginxspec: type: NodePort ports:-name: http port: 80 targetPort: 80 protocol: TCP nodePort: 30080-name: https port: 443 targetPort: 443 protocol: TCP nodePort: 30443 selector: app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/ Part-of: ingress-nginx# App configuration kubectl apply-f service-nodeport.yaml# View kubectl get svc-n ingress-nginx
Access: ip:30080 in an external browser
The reason for reporting an error at this time is that no ingress rule associated with ingress-controller to service-B has been generated
6. Define ingress rules
Define ingress rules, during which rules are automatically injected into the nginx.conf of ingress-controller (pod)
Ingress-controller is directly related to service-B, but ingress generates various rules in the middle.
Vim ingress-myapp.yamlapiVersion: extensions/v1beta1kind: Ingressmetadata: name: ingress-myapp namespace: default annotations: kubernetes.io/ingress.class: "nginx" spec: rules:-host: myapp.magedu.com http: paths:-path: backend: serviceName: myapp servicePort: 80
At this point, the nginx.conf of ingress-controller will automatically generate a configuration of server segment, that is, a field of virtual host of nginx, including upstream configuration, etc.
Upstream automatically proxies to backend pod (pod-B), which are automatically generated, so automatically generate configuration, automatically change configuration, etc.
You just need to change this yaml file
# Application configuration kubectl apply-f ingress-myapp.yaml
Configure host files on external hosts
Then visit it in the browser and find that you can already access the back-end pod.
Second, use https
1. Create a K8s certificate (note that the same namespace is used as the backend pod)
Kubectl-n default create secret tls ingress-test-key / home/centos/cert/cash532.key-cert/ home/centos/cert/cash532.crt
2. Create ingress rules
Pay attention to the similarity of namespace, otherwise the certificate will not be valid
Vim ingress-myapp-cash532.yamlapiVersion: extensions/v1beta1kind: Ingressmetadata: name: ingress-myapp namespace: default annotations: kubernetes.io/ingress.class: "nginx" kubernetes.io/secure-backends: "true" kubernetes.io/ssl-passthrough: "true" spec: tls:-hosts:-myapp.cash532.xyz secretName: ingress-test rules:-host: myapp.cash532.xyz http: paths:-path: Backend: serviceName: myapp servicePort: 8 applications configuration kubectl apply-f ingress-myapp-cash532.yaml
Browser access
This is the end of the content of "what is the method of deploying ingress-nginx in K8s". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.