潇湘夜雨移动版

主页 > 系统 > 云计算与云原生 >

ingress控制器(4)

[root@master ingress]# kubectl describe pod nginx-ingress-controller-7b6c66657d-4cxq8 -n ingress-nginx
Name:               nginx-ingress-controller-7b6c66657d-4cxq8
Namespace:          ingress-nginx
Priority:           0
PriorityClassName:  <none>
Node:               node2.k8s/192.168.0.22
Start Time:         Sun, 05 Jul 2020 17:24:31 +0800
Labels:             app.kubernetes.io/name=ingress-nginx
                    app.kubernetes.io/part-of=ingress-nginx
                    pod-template-hash=7b6c66657d
Annotations:        kubernetes.io/limit-ranger: LimitRanger plugin set: cpu, memory request for container nginx-ingress-controller
                    prometheus.io/port: 10254
                    prometheus.io/scrape: true
Status:             Pending
IP:                 10.244.2.57
Controlled By:      ReplicaSet/nginx-ingress-controller-7b6c66657d
 
Events:
  Type     Reason     Age                   From                Message
  ----     ------     ----                  ----                -------
  Normal   Scheduled  3m51s                 default-scheduler   Successfully assigned ingress-nginx/nginx-ingress-controller-7b6c66657d-4cxq8 to node2.k8s
  Warning  Failed     3m32s                 kubelet, node2.k8s  Failed to pull image "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0": rpc error: code = Unknown desc 
= Error response from daemon: Get https://quay.io/v2/kubernetes-ingress-controller/nginx-ingress-controller/manifests/0.30.0: net/http: TLS handshake timeout  Warning  Failed     2m21s (x2 over 3m4s)  kubelet, node2.k8s  Failed to pull image "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0": rpc error: code = Unknown desc 
= Error response from daemon: Get https://quay.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)  Normal   Pulling    94s (x4 over 3m50s)   kubelet, node2.k8s  pulling image "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0"
  Warning  Failed     72s (x4 over 3m32s)   kubelet, node2.k8s  Error: ErrImagePull
  Warning  Failed     72s                   kubelet, node2.k8s  Failed to pull image "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0": rpc error: code = Unknown desc 
= error pulling image configuration: Get https://quay.io/v2/kubernetes-ingress-controller/nginx-ingress-controller/blobs/sha256:89ccad40ce8e413ff4ceba362de33a81da1f1c5b4c909200c37898781236ef30: net/http: TLS handshake timeout  Normal   BackOff    61s (x6 over 3m32s)   kubelet, node2.k8s  Back-off pulling image "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0"
  Warning  Failed     49s (x7 over 3m32s)   kubelet, node2.k8s  Error: ImagePullBackOff
  
  
 三、使用ingress发布tomcat
 
 1、部署 tomcat 实例和services资源
 
 Ingress 资源仅通过 Service 资源识别相应的 Pod 资源, 获取其 IP 和端口,而 Ingress
控制器即可直接使用各 Pod 对象的 IP 地址与它直接进行通信,而不经由 Se vice 资源的代
理和调度,因 Service资源的 lu sterIP ngress 控制器来说一无所用
 
 [root@master ingress]# vim tomcat-deploy.yaml 
 
apiVersion: v1
kind: Service
metadata:
  name: tomcat
  namespace: default
spec:
  selector:
   app: tomcat
   release: canary
  ports:
  - name: http
    targetPort: 8080
    port: 8080
  - name: ajp
    targetPort: 8009
    port: 8009
 
---
 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deploy
  namespace: default
spec:
  replicas: 1
  selector:
   matchLabels:
     app: tomcat
     release: canary
  template:
   metadata:
     labels:
       app: tomcat
       release: canary
   spec:
     containers:
     - name: tomcat
       image: tomcat
 
apiVersion: v1
kind: Service
metadata:
  name: tomcat
  namespace: default
spec:
  selector:
   app: tomcat
   release: canary
  ports:
  - name: http
    targetPort: 8080
    port: 8080
  - name: ajp
    targetPort: 8009
    port: 8009
 
---
 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-deploy
  namespace: default
spec:
  replicas: 1
  selector:
   matchLabels:
     app: tomcat
     release: canary
  template:
   metadata:
     labels:
       app: tomcat
       release: canary
   spec:
     containers:
     - name: tomcat
       image: tomcat
       ports:
       - name: http
         containerPort: 8080
 
[root@master ingress]# kubectl apply -f tomcat-deploy.yaml
[root@master ingress]# kubectl get pod -l app=tomcat
NAME                            READY   STATUS    RESTARTS   AGE
tomcat-deploy-5b7878569-gh4v7   1/1     Running   0          150m
 
[root@master ingress]# kubectl get svc tomcat
NAME     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
tomcat   ClusterIP   10.101.95.117   <none>        8080/TCP,8009/TCP   160m
 
2、创建 Ingress 资源
 
[root@master ingress]# vim ingress-tomcat.yaml 
 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-tomcat
  annotations:
    kubernets.io/ingress.class: "nginx"
spec:
  rules:
  - host: tomcat.lzh.com
    http:
      paths:
      - path:
        backend:
          serviceName: tomcat
          servicePort: 8080
 
3、测试
[root@master ingress]# kubectl get pods -n ingress-nginx -o wide
NAME                                        READY   STATUS    RESTARTS   AGE     IP             NODE        NOMINATED NODE   READINESS GATES (责任编辑:liangzh)