ingress-nginx安装
##我用的是0.15.0版本的,己住千万不要用最新版本,太xx坑比了!!!
一:下载ingress包
链接:https://pan.baidu.com/s/1HbcJdCALntA9xDFJQF3Tkg
提取码:htu8
[root@master ~]# tar xf ingress-nginx-nginx-0.15.0.tar.gz [root@master ~]# cd ingress-nginx-nginx-0.15.0
[root@master ingress-nginx-nginx-0.15.0]# cd deploy/
[root@master deploy]# ls
configmap.yaml namespace.yaml publish-service-patch.yaml README.md udp-services-configmap.yaml with-rbac.yaml default-backend.yaml provider rbac.yaml tcp-services-configmap.yaml without-rbac.yaml
[root@hd01 deploy]#
[root@master deploy]# kubectl apply -f ./
[root@master deploy]# kubectl provider/baremetal/service-nodeport.yaml
等带节点下载完镜像后
##当镜像下载完启动完毕后,会看到这样的结果
[root@master deploy]# kubectl get svc -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default-http-backend ClusterIP 10.98.147.56 <none> 80/TCP 20h ingress-nginx NodePort 10.101.121.183 <none> 80:31502/TCP,443:31061/TCP 135m [root@master deploy]# kubectl get pod -n ingress-nginx NAME READY STATUS RESTARTS AGE default-http-backend-5d4f569658-zhhn4 1/1 Running 0 20h nginx-ingress-controller-54b8f8d8cd-5bj65 1/1 Running 0 20h [root@master deploy]#
此时我们的ingress-nginx已经安装好了,下面我们来做一个测试
建立yaml文件生成pod及serviece [root@master ingress]# cat svc-pod.yaml apiVersion: v1 kind: Service metadata: name: myapp namespace: default spec: selector: app: myapp release: canary ports: - name: http targetPort: 80 port: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: myapp-deploy namespace: default spec: 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: 80 ##建立一个ingerss的文件
[root@master ingress]# cat ingress-myapp.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: 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
[root@master ingress]# kubectl apply -f svc-pod.yaml [root@master ingress]# kubectl apply -f ingress-myapp.yaml [root@master ingress]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 15d myapp ClusterIP 10.105.80.232 <none> 80/TCP 138m [root@master ingress]# kubectl get pod NAME READY STATUS RESTARTS AGE myapp-deploy-6b56d98b6b-7shgg 1/1 Running 0 138m myapp-deploy-6b56d98b6b-9zx5h 1/1 Running 0 138m myapp-deploy-6b56d98b6b-ftcxc 1/1 Running 0 138m [root@master ingress]#
[root@hd01 ingress]# kubectl get pod -n ingress-nginx NAME READY STATUS RESTARTS AGE default-http-backend-5d4f569658-zhhn4 1/1 Running 0 20h nginx-ingress-controller-54b8f8d8cd-5bj65 1/1 Running 0 20h [root@hd01 ingress]# kubectl exec -n ingress-nginx -it nginx-ingress-controller-54b8f8d8cd-5bj65 -- /bin/sh # ce / /bin/sh: 1: ce: not found # cd /etc/nginx # ls fastcgi.conf fastcgi_params.default koi-win mime.types.default nginx.conf scgi_params uwsgi_params fastcgi.conf.default geoip lua modsecurity nginx.conf.default scgi_params.default uwsgi_params.default fastcgi_params koi-utf mime.types modules owasp-modsecurity-crs template win-utf # cat nginx.conf --- upstream default-myapp-80 { least_conn; keepalive 32; server 10.244.2.54:80 max_fails=0 fail_timeout=0; server 10.244.1.49:80 max_fails=0 fail_timeout=0; server 10.244.1.48:80 max_fails=0 fail_timeout=0; } --- ## start server myapp.magedu.com server { server_name myapp.magedu.com ; listen 80; listen [::]:80; set $proxy_upstream_name "-"; location / { log_by_lua_block { } port_in_redirect off; set $proxy_upstream_name "default-myapp-80"; set $namespace "default"; set $ingress_name "ingress-myapp"; set $service_name "myapp";
此时我们就可以通过外部浏览器访问域名访问了
首先我们在windows上做好本地的地址解析《hosts》