k8s v1.16.2中部署ingress-nginx

环境与软件版本

OS

Centos 7

软件

ingress-nginx

https://github.com/kubernetes/ingress-nginx (commit:43fa61cabdba39f81c0f3d38edc8bdb5892027f1)

k8s

使用kubeadm部署k8s(v1.16.2)

安装

修改配置文件

修改deploy/baremetal/service-nodeport.yaml

diff --git a/deploy/baremetal/service-nodeport.yaml b/deploy/baremetal/service-nodeport.yaml
index 0aadea157..d0b20c7ce 100644
--- a/deploy/baremetal/service-nodeport.yaml
+++ b/deploy/baremetal/service-nodeport.yaml
@@ -2,6 +2,10 @@ apiVersion: v1
 kind: Service
 metadata:
   name: ingress-nginx
+  namespace: ingress-nginx
+  labels:
+    app.kubernetes.io/name: ingress-nginx
+    app.kubernetes.io/part-of: ingress-nginx
 spec:
   type: NodePort
   ports:
@@ -13,4 +17,7 @@ spec:
       port: 443
       targetPort: 443
       protocol: TCP
+  selector:
+    app.kubernetes.io/name: ingress-nginx
+    app.kubernetes.io/part-of: ingress-nginx
   externalTrafficPolicy: Cluster

k8s部署

kubectl apply -f deploy/static/mandatory.yaml

kubectl apply -f deploy/baremetal/service-nodeport.yaml

检查相关

查看版本与日志

[root@master ~]# POD_NAMESPACE=ingress-nginx
[root@master ~]# POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io/name=ingress-nginx -o jsonpath='{.items[0].metadata.name}')
[root@master ~]# kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version
-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       0.26.1
  Build:         git-2de5a893a
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: openresty/1.15.8.2

-------------------------------------------------------------------------------

[root@master ~]# kubectl logs $POD_NAME -n $POD_NAMESPACE 
-------------------------------------------------------------------------------
NGINX Ingress controller
  Release:       0.26.1
  Build:         git-2de5a893a
  Repository:    https://github.com/kubernetes/ingress-nginx
  nginx version: openresty/1.15.8.2

-------------------------------------------------------------------------------

W1028 09:24:05.910002       6 flags.go:243] SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)
W1028 09:24:05.910076       6 client_config.go:541] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
I1028 09:24:05.910219       6 main.go:182] Creating API client for https://10.96.0.1:443
I1028 09:24:05.925944       6 main.go:226] Running in Kubernetes cluster version v1.16 (v1.16.2) - git (clean) commit c97fe5036ef3df2967d086711e6c0c405941e14b - platform linux/amd64
I1028 09:24:06.061554       6 main.go:101] SSL fake certificate created /etc/ingress-controller/ssl/default-fake-certificate.pem
I1028 09:24:06.093690       6 nginx.go:263] Starting NGINX Ingress controller
I1028 09:24:06.104938       6 event.go:255] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"ingress-nginx", Name:"nginx-configuration", UID:"3b8dc460-9712-47a4-a367-79221a33b8c7", APIVersion:"v1", ResourceVersion:"549143", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap ingress-nginx/nginx-configuration
I1028 09:24:06.104966       6 event.go:255] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"ingress-nginx", Name:"udp-services", UID:"1b8ed74c-48fb-4c59-8826-c396ff31c426", APIVersion:"v1", ResourceVersion:"549146", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap ingress-nginx/udp-services
I1028 09:24:06.104972       6 event.go:255] Event(v1.ObjectReference{Kind:"ConfigMap", Namespace:"ingress-nginx", Name:"tcp-services", UID:"599e7cd5-3e61-46f6-b85a-e0864388fc4f", APIVersion:"v1", ResourceVersion:"549145", FieldPath:""}): type: 'Normal' reason: 'CREATE' ConfigMap ingress-nginx/tcp-services
I1028 09:24:07.294484       6 nginx.go:307] Starting NGINX process
I1028 09:24:07.295550       6 leaderelection.go:241] attempting to acquire leader lease  ingress-nginx/ingress-controller-leader-nginx...
I1028 09:24:07.296504       6 controller.go:134] Configuration changes detected, backend reload required.
I1028 09:24:07.310777       6 leaderelection.go:251] successfully acquired lease ingress-nginx/ingress-controller-leader-nginx
I1028 09:24:07.311273       6 status.go:86] new leader elected: nginx-ingress-controller-568867bf56-z7p9b
I1028 09:24:07.365169       6 controller.go:150] Backend successfully reloaded.
I1028 09:24:07.365189       6 controller.go:159] Initial sync, sleeping for 1 second.

访问服务

[root@master ~]# kubectl get svc -n ingress-nginx
NAME            TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx   NodePort   10.101.220.156           80:31971/TCP,443:32151/TCP   106m
[root@master ~]# curl http://10.101.220.156

404 Not Found

404 Not Found


openresty/1.15.8.2

curl到的结果是404,就完成ingress-nginx部署。

你可能感兴趣的:(Linux,Container,kubernetes)