k8s nginx-ingress部署
Posted 青衫解衣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s nginx-ingress部署相关的知识,希望对你有一定的参考价值。
两种方式部署k8s nginx-ingress:
1.heml源安装
2.yaml安装
Heml安装ingress-nginx:
目前测试集群1.17.17,最新版的ingress-nginx是安装不了的。
ingress所支持的k8s版本:
https://github.com/kubernetes/ingress-nginx
git拉取kubernetes-ingress仓库:
[root@master ingress-nginx]# git clone https://github.com/nginxinc/kubernetes-ingress/
添加nginx-stable源:
[root@master helm-chart]# helm repo add nginx-stable https://helm.nginx.com/stable
"nginx-stable" has been added to your repositories
通过helm安装nginx-ingress:
[root@master helm-chart]# pwd
/root/ingress/ingress-nginx/kubernetes-ingress/deployments/helm-chart
[root@master helm-chart]# helm install my-release nginx-stable/nginx-ingress
NAME: my-release
LAST DEPLOYED: Thu Sep 2 22:48:22 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The NGINX Ingress Controller has been installed.
安装时可以指定参数:
[root@master helm-chart]# helm install nginx-ingress nginx-stable/nginx-ingress --set rbac.create=true,--set controller.service.loadBalancerIPs[0]=10.40.42.103,--namespace=ingress-nginx
Error: expected at most two arguments, unexpected arguments: controller.service.loadBalancerIPs[0]=10.40.42.103,--namespace=ingress-nginx
[root@master helm-chart]# helm install nginx-ingress nginx-stable/nginx-ingress --set rbac.create=true,--namespace=ingress-nginx
NAME: nginx-ingress
LAST DEPLOYED: Fri Sep 3 02:23:54 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The NGINX Ingress Controller has been installed.
通过github yaml文件安装:
V11目录代表安装ingress 1.11版本,自己建的方便区分.
切换到一下目录:
/root/v11/kubernetes-ingress/deployments/helm-chart
修改values.yaml配置文件:
参数根据个人需要调整。
执行安装:
helm install my-release .
查看当前ingress-contro的ingress-class:
[root@master helm-chart]# kubectl get deploy -n default -o yaml | grep class
- -ingress-class=nginx-test
- -use-ingress-class-only=false
查看ingress service状态:
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d7h
my-release-nginx-ingress LoadBalancer 10.97.160.13 10.40.42.103 80:32419/TCP,443:31679/TCP 118m
安装测试应用nginx:
[root@master nginx-app]# kubectl apply -f base.yaml
namespace/nginx-example created
deployment.apps/nginx-deployment created
service/my-nginx created
查看nginx pod状态:
[root@master nginx-app]# kubectl get pod -A | grep nginx-example
nginx-example nginx-deployment-7cd5ddccc7-5vw2b 1/1 Running 0 53s
nginx-example nginx-deployment-7cd5ddccc7-84x6q 1/1 Running 0 53s
查看nginx service状态:
[root@master nginx-app]# kubectl get svc -A | grep nginx-example
nginx-example my-nginx ClusterIP 10.106.91.145 <none> 80/TCP 62s
创建nginx测试的案例的ingress:
[root@master ~]# kubectl apply -f ingresstest.yaml
ingress.extensions/ingress-test created
[root@master ~]# cat ingresstest.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-test
namespace: nginx-example
annotations:
kubernetes.io/ingress.class: "nginx-test"
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: test2.example.com
http:
paths:
- path: /
backend:
serviceName: mys-nginx
servicePort: 80
查看ingress的状态:
[root@master ~]# kubectl get ing -A
NAMESPACE NAME HOSTS ADDRESS PORTS AGE
nginx-example ingress-test test2.example.com 10.40.42.103 80 32m
本地配置解析:
10.40.42.103 test2.example.com
浏览器测试访问:
以上是关于k8s nginx-ingress部署的主要内容,如果未能解决你的问题,请参考以下文章