ingress

来源:6-6 部署ingress-nginx(下)

StudyExchange

2020-03-30

[root@k8s-master tf-serving]# kubectl get nodes
NAME           STATUS   ROLES    AGE    VERSION
k8s-master     Ready    master   3d5h   v1.18.0
worker-node1   Ready    <none>   3d4h   v1.18.0
worker-node2   Ready    <none>   3d4h   v1.18.0
[root@k8s-master tf-serving]# kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
apps-hpt     ClusterIP   10.98.26.5   <none>        8501/TCP   13m
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP    60m
[root@k8s-master tf-serving]# kubectl get deployments
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
apps-hpt   2/2     2            2           13m
[root@k8s-master tf-serving]# kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
apps-hpt-5759d78544-dqftn   1/1     Running   0          12m
apps-hpt-5759d78544-gtthn   1/1     Running   0          13m
[root@k8s-master tf-serving]# kubectl get all -n ingress-nginx
NAME                                            READY   STATUS    RESTARTS   AGE
pod/nginx-ingress-controller-77db54fc46-wdfsc   1/1     Running   0          51m

NAME                    TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/ingress-nginx   NodePort   10.103.23.194   <none>        80:31443/TCP,443:30858/TCP   4h51m

NAME                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx-ingress-controller   1/1     1            1           4h55m

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-ingress-controller-5bb8fb4bb6   0         0         0       4h55m
replicaset.apps/nginx-ingress-controller-77db54fc46   1         1         1       51m
[root@k8s-master tf-serving]# netstat -ntlp|grep 80
tcp        0      0 172.31.10.88:2380       0.0.0.0:*               LISTEN      1749/etcd

我有1主2从的集群,上面部署了一个app-hpt的API集群,我想通过ingress-nginx让外网可以访问app-hpt。然后我按照视频,

  1. 给node打标签kubectl label node k8s-master app=ingress
  2. 修改mandatory.yaml的
     serviceAccountName: nginx-ingress-serviceaccount
     hostNetwork: true
     nodeSelector:
       app: ingress

并执行(试了好多次,所以除了最后一个是configured,其他都是unchanged)

[root@k8s-master tf-serving]# kubectl apply -f mandatory.yaml 
namespace/ingress-nginx unchanged
configmap/nginx-configuration unchanged
configmap/tcp-services unchanged
configmap/udp-services unchanged
serviceaccount/nginx-ingress-serviceaccount unchanged
clusterrole.rbac.authorization.k8s.io/nginx-ingress-clusterrole unchanged
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 unchanged
limitrange/ingress-nginx configured

但是80端口并没有nginx在使用,我该如何一步一步检查配置,以便让ingress-nginx可用,求指导!

写回答

1回答

刘果国

2020-03-31

你好,可以从几方面检查:

首先检查一下服务运行情况,可以直接访问ingress-nginx的pod的80端口看是否可以联通。

在检查一下pod运行在哪个节点。docker ps确认一下nginx运行状态,进一步可以docker inspect检查一下docker容器的网络,是否是host模式运行。

另外可以参考课程的配置(用host模式运行的):https://git.imooc.com/coding-335/course-docs/src/master/5/mandatory.yaml

0
2
刘果国
回复
StudyExchange
我是在本地机房部署的。阿里云上没部署过。但阿里云上ingress-nginx肯定是可以正常用的
2020-04-01
共2条回复

Kubernetes生产落地全程实践

一个互联网公司落地Kubernetes全过程点点滴滴

2293 学习 · 2216 问题

查看课程