Google上的nginx-ingress k8s没有IP地址

时间:2019-03-04 10:23:52

标签: docker nginx kubernetes

我正在按照ingress chapter来练习k8s。我正在使用Google Cluster。规格如下

master1.11.7-gke.4
node1.11.7-gke.4

$ kubectl get nodes -o wide
NAME                                   STATUS   ROLES    AGE   VERSION         INTERNAL-IP   EXTERNAL-IP      OS-IMAGE                             KERNEL-VERSION   CONTAINER-RUNTIME
gke-singh-default-pool-a69fa545-1sm3   Ready    <none>   6h    v1.11.7-gke.4   10.148.0.46   35.197.128.107   Container-Optimized OS from Google   4.14.89+         docker://17.3.2
gke-singh-default-pool-a69fa545-819z   Ready    <none>   6h    v1.11.7-gke.4   10.148.0.47   35.198.217.71    Container-Optimized OS from Google   4.14.89+         docker://17.3.2
gke-singh-default-pool-a69fa545-djhz   Ready    <none>   6h    v1.11.7-gke.4   10.148.0.45   35.197.159.75    Container-Optimized OS from Google   4.14.89+         docker://17.3.2

master endpoint35.186.148.93

DNS:singh.hbot.io(主IP)

为了使我的问题简短。我将我的源代码发布到代码段中,并返回到此处。

文件:

deployment.yaml ingress.yaml ingress-rules.yaml

问题:
curl http://singh.hbot.io/webapp1超时

说明

$ kubectl get deployment -n nginx-ingress
NAME            DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-ingress   1         1         1            0           2h

nginx-ingress部署不可用。

$ kubectl describe deployment -n nginx-ingress
Name:                   nginx-ingress
Namespace:              nginx-ingress
CreationTimestamp:      Mon, 04 Mar 2019 15:09:42 +0700
Labels:                 app=nginx-ingress
Annotations:            deployment.kubernetes.io/revision: 1
                        kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"extensions/v1beta1","kind":"Deployment","metadata":{"annotations":{},"name":"nginx-ingress","namespace":"nginx-ingress"},"s...
Selector:               app=nginx-ingress
Replicas:               1 desired | 1 updated | 1 total | 0 available | 1 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  1 max unavailable, 1 max surge
Pod Template:
  Labels:           app=nginx-ingress
  Service Account:  nginx-ingress
  Containers:
   nginx-ingress:
    Image:       nginx/nginx-ingress:edge
    Ports:       80/TCP, 443/TCP
    Host Ports:  0/TCP, 0/TCP
    Args:
      -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
      -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
    Environment:
      POD_NAMESPACE:   (v1:metadata.namespace)
      POD_NAME:        (v1:metadata.name)
    Mounts:           <none>
  Volumes:            <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-ingress-77fcd48f4d (1/1 replicas created)
Events:          <none>

豆荚:

$ kubectl get pods --all-namespaces=true
NAMESPACE       NAME                                              READY   STATUS             RESTARTS   AGE
default         webapp1-7d67d68676-k9hhl                          1/1     Running            0          6h
default         webapp2-64d4844b78-9kln5                          1/1     Running            0          6h
default         webapp3-5b8ff7484d-zvcsf                          1/1     Running            0          6h
kube-system     event-exporter-v0.2.3-85644fcdf-xxflh             2/2     Running            0          6h
kube-system     fluentd-gcp-scaler-8b674f786-gvv98                1/1     Running            0          6h
kube-system     fluentd-gcp-v3.2.0-srzc2                          2/2     Running            0          6h
kube-system     fluentd-gcp-v3.2.0-w2z2q                          2/2     Running            0          6h
kube-system     fluentd-gcp-v3.2.0-z7p9l                          2/2     Running            0          6h
kube-system     heapster-v1.6.0-beta.1-5685746c7b-kd4mn           3/3     Running            0          6h
kube-system     kube-dns-6b98c9c9bf-6p8qr                         4/4     Running            0          6h
kube-system     kube-dns-6b98c9c9bf-pffpt                         4/4     Running            0          6h
kube-system     kube-dns-autoscaler-67c97c87fb-gbgrs              1/1     Running            0          6h
kube-system     kube-proxy-gke-singh-default-pool-a69fa545-1sm3   1/1     Running            0          6h
kube-system     kube-proxy-gke-singh-default-pool-a69fa545-819z   1/1     Running            0          6h
kube-system     kube-proxy-gke-singh-default-pool-a69fa545-djhz   1/1     Running            0          6h
kube-system     l7-default-backend-7ff48cffd7-trqvx               1/1     Running            0          6h
kube-system     metrics-server-v0.2.1-fd596d746-bvdfk             2/2     Running            0          6h
kube-system     tiller-deploy-57c574bfb8-xnmtj                    1/1     Running            0          1h
nginx-ingress   nginx-ingress-77fcd48f4d-rfwbk                    0/1     CrashLoopBackOff   35         2h

描述广告连播

$ kubectl describe pods -n nginx-ingress
Name:               nginx-ingress-77fcd48f4d-5rhtv
Namespace:          nginx-ingress
Priority:           0
PriorityClassName:  <none>
Node:               gke-singh-default-pool-a69fa545-djhz/10.148.0.45
Start Time:         Mon, 04 Mar 2019 17:55:00 +0700
Labels:             app=nginx-ingress
                    pod-template-hash=3397804908
Annotations:        <none>
Status:             Running
IP:                 10.48.2.10
Controlled By:      ReplicaSet/nginx-ingress-77fcd48f4d
Containers:
  nginx-ingress:
    Container ID:  docker://5d3ee9e2bf7a2060ff0a96fdd884a937b77978c137df232dbfd0d3e5de89fe0e
    Image:         nginx/nginx-ingress:edge
    Image ID:      docker-pullable://nginx/nginx-ingress@sha256:16c1c6dde0b904f031d3c173e0b04eb82fe9c4c85cb1e1f83a14d5b56a568250
    Ports:         80/TCP, 443/TCP
    Host Ports:    0/TCP, 0/TCP
    Args:
      -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
      -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    255
      Started:      Mon, 04 Mar 2019 18:16:33 +0700
      Finished:     Mon, 04 Mar 2019 18:16:33 +0700
    Ready:          False
    Restart Count:  9
    Environment:
      POD_NAMESPACE:  nginx-ingress (v1:metadata.namespace)
      POD_NAME:       nginx-ingress-77fcd48f4d-5rhtv (v1:metadata.name)
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from nginx-ingress-token-zvcwt (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  nginx-ingress-token-zvcwt:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  nginx-ingress-token-zvcwt
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                  From                                           Message
  ----     ------     ----                 ----                                           -------
  Normal   Scheduled  26m                  default-scheduler                              Successfully assigned nginx-ingress/nginx-ingress-77fcd48f4d-5rhtv to gke-singh-default-pool-a69fa545-djhz
  Normal   Created    25m (x4 over 26m)    kubelet, gke-singh-default-pool-a69fa545-djhz  Created container
  Normal   Started    25m (x4 over 26m)    kubelet, gke-singh-default-pool-a69fa545-djhz  Started container
  Normal   Pulling    24m (x5 over 26m)    kubelet, gke-singh-default-pool-a69fa545-djhz  pulling image "nginx/nginx-ingress:edge"
  Normal   Pulled     24m (x5 over 26m)    kubelet, gke-singh-default-pool-a69fa545-djhz  Successfully pulled image "nginx/nginx-ingress:edge"
  Warning  BackOff    62s (x112 over 26m)  kubelet, gke-singh-default-pool-a69fa545-djhz  Back-off restarting failed container

修复容器已终止
command添加到ingress.yaml以防止container完成运行并被k8s终止。 command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]

Ingress没有来自GKE的IP地址。让我看看细节

描述入口:

$ kubectl describe ing
Name:             webapp-ingress
Namespace:        default
Address:
Default backend:  default-http-backend:80 (10.48.0.8:8080)
Rules:
  Host  Path  Backends
  ----  ----  --------
  *
        /webapp1   webapp1-svc:80 (<none>)
        /webapp2   webapp2-svc:80 (<none>)
                   webapp3-svc:80 (<none>)
Annotations:
  kubectl.kubernetes.io/last-applied-configuration:  {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{},"name":"webapp-ingress","namespace":"default"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"webapp1-svc","servicePort":80},"path":"/webapp1"},{"backend":{"serviceName":"webapp2-svc","servicePort":80},"path":"/webapp2"},{"backend":{"serviceName":"webapp3-svc","servicePort":80}}]}}]}}

Events:
  Type     Reason     Age                     From                     Message
  ----     ------     ----                    ----                     -------
  Warning  Translate  7m45s (x59 over 4h20m)  loadbalancer-controller  error while evaluating the ingress spec: service "default/webapp1-svc" is type "ClusterIP", expected "NodePort" or "LoadBalancer"; service "default/webapp2-svc" is type "ClusterIP", expected "NodePort" or "LoadBalancer"; service "default/webapp3-svc" is type "ClusterIP", expected "NodePort" or "LoadBalancer"

从这一行中,我得到了Christian Roy的所有最终解决方案。

修复ClusterIP 这是默认值,然后我必须使用NodePort来编辑清单文件

apiVersion: v1
kind: Service
metadata:
  name: webapp1-svc
  labels:
    app: webapp1
spec:
  type: NodePort
  ports:
  - port: 80
  selector:
    app: webapp1

就是这样。

2 个答案:

答案 0 :(得分:3)

答案在您的问题中。您的入口的描述显示了问题所在。

您做了kubectl describe ing,该输出的最后一部分是:

Events:
  Type     Reason     Age                     From                     Message
  ----     ------     ----                    ----                     -------
  Warning  Translate  7m45s (x59 over 4h20m)  loadbalancer-controller  error while evaluating the ingress spec: service "default/webapp1-svc" is type "ClusterIP", expected "NodePort" or "LoadBalancer"; service "default/webapp2-svc" is type "ClusterIP", expected "NodePort" or "LoadBalancer"; service "default/webapp3-svc" is type "ClusterIP", expected "NodePort" or "LoadBalancer"

重要的部分是:

  

评估入口规范时出错:服务“ default / webapp1-svc”的类型为“ ClusterIP”,预期为“ NodePort”或“ LoadBalancer”

解决方案

只需将您的所有服务更改为NodePort类型,它就会起作用。

答案 1 :(得分:0)

我必须添加command才能使容器无法正常工作。

command: [ "/bin/bash", "-ce", "tail -f /dev/null" ]