【原】二进制部署 k8s 1.18.3 (13)

给对应节点打标签

[root@centos7-nginx ~]# kubectl label nodes centos7-d lb-type=nginx node/centos7-d labeled [root@centos7-nginx ~]# kubectl label nodes centos7-e lb-type=nginx node/centos7-e labeled 3.16.2 安装

本次实验采用默认的方式:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/deploy.yaml

如果需要进行修改,先下载到本地

[root@centos7-nginx yaml]# wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/deploy.yaml [root@centos7-nginx yaml]# vim deploy.yaml [root@centos7-nginx yaml]# kubectl apply -f deploy.yaml namespace/ingress-nginx created serviceaccount/ingress-nginx created configmap/ingress-nginx-controller created clusterrole.rbac.authorization.k8s.io/ingress-nginx created clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created role.rbac.authorization.k8s.io/ingress-nginx created rolebinding.rbac.authorization.k8s.io/ingress-nginx created service/ingress-nginx-controller-admission created service/ingress-nginx-controller created deployment.apps/ingress-nginx-controller created validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created job.batch/ingress-nginx-admission-create created job.batch/ingress-nginx-admission-patch created role.rbac.authorization.k8s.io/ingress-nginx-admission created rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created serviceaccount/ingress-nginx-admission created

也可以先跑起来,在修改

[root@centos7-nginx ~]# kubectl edit deploy ingress-nginx-controller -n ingress-nginx ... spec: progressDeadlineSeconds: 600 replicas: 2 #----> 修改为 2 实现高可用 ... template: ... spec: nodeSelector: #----> 增加节点选择器 lb-type: nginx #----> 匹配标签

或者使用

[root@centos7-nginx yaml]# kubectl -n ingress-nginx patch deployment ingress-nginx-controller -p '{"spec": {"template": {"spec": {"nodeSelector": {"lb-type": "nginx"}}}}}' deployment.apps/ingress-nginx-controller patched [root@centos7-nginx yaml]# kubectl -n ingress-nginx scale --replicas=2 deployment/ingress-nginx-controller deployment.apps/ingress-nginx-controller scaled

查看 svc 状态可以看到端口已经分配

[root@centos7-nginx ~]# kubectl get svc -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-controller NodePort 10.101.121.120 <none> 80:36459/TCP,443:33171/TCP 43m ingress-nginx-controller-admission ClusterIP 10.111.108.89 <none> 443/TCP 43m

所有机器上的端口也已经开启,为了防止请求被丢弃,建议将代理后的节点 ip 固定在已经打了lb-type=nginx的节点

[root@centos7-a ~]# netstat -ntpl |grep proxy tcp 0 0 0.0.0.0:36459 0.0.0.0:* LISTEN 69169/kube-proxy tcp 0 0 0.0.0.0:33171 0.0.0.0:* LISTEN 69169/kube-proxy ... [root@centos7-d ~]# netstat -ntpl |grep proxy tcp 0 0 0.0.0.0:36459 0.0.0.0:* LISTEN 84181/kube-proxy tcp 0 0 0.0.0.0:33171 0.0.0.0:* LISTEN 84181/kube-proxy [root@centos7-e ~]# netstat -ntpl |grep proxy tcp 0 0 0.0.0.0:36459 0.0.0.0:* LISTEN 74881/kube-proxy tcp 0 0 0.0.0.0:33171 0.0.0.0:* LISTEN 74881/kube-proxy 3.16.3 验证 # 创建一个应用 [root@centos7-nginx ~]# kubectl create deployment nginx-dns --image=nginx deployment.apps/nginx-dns created # 创建 svc [root@centos7-nginx ~]# kubectl expose deployment nginx-dns --port=80 service/nginx-dns exposed [root@centos7-nginx ~]# kubectl get pods NAME READY STATUS RESTARTS AGE busybox 1/1 Running 29 29h nginx-dns-5c6b6b99df-qvnjh 1/1 Running 0 13s [root@centos7-nginx ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d5h nginx-dns ClusterIP 10.108.88.75 <none> 80/TCP 10s # 创建 ingress 文件并执行 [root@centos7-nginx yaml]# vim ingress.yaml [root@centos7-nginx yaml]# cat ingress.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-nginx-dns namespace: default annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: ng.5179.top http: paths: - path: / backend: serviceName: nginx-dns servicePort: 80 [root@centos7-nginx yaml]# kubectl apply -f ingress.yaml ingress.extensions/ingress-nginx-dns created [root@centos7-nginx yaml]# kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE ingress-nginx-dns <none> ng.5179.top 80 9s

先将日志刷起来

[root@centos7-nginx yaml]# kubectl get pods NAME READY STATUS RESTARTS AGE busybox 1/1 Running 30 30h nginx-dns-5c6b6b99df-qvnjh 1/1 Running 0 28m [root@centos7-nginx yaml]# kubectl logs -f nginx-dns-5c6b6b99df-qvnjh /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Configuration complete; ready for start up 10.244.3.123 - - [20/Jun/2020:12:58:20 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "10.244.4.0"

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzyxyd.html