linux怎么查看本机内存大小
291
2022-10-23
ingress暴露服务部署
部署deployment pod应用
ingress 通过自有的控制器ingress-controller来动态加载nginx配置,使service可以将deployment下发的pod应用以~]# vim nginx-deploy.yaml apiVersion: apps/v1kind: Deploymentmetadata: name: front-end labels: app: nginxspec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
[root@k8s-master ~]# kubectl apply -f nginx-deploy.yaml[root@k8s-master ~]# kubectl get deployNAME READY UP-TO-DATE AVAILABLE AGEfront-end 3/3 3 3 177m[root@k8s-master ~]# kubectl get pod -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESfront-end-6b7b5c4bfc-48b8x 1/1 Running 0 177m 10.224.169.135 k8s-node2
[root@k8s-master ~]# kubectl apply -f nginx-deploy.yaml[root@k8s-master ~]# kubectl get deployNAME READY UP-TO-DATE AVAILABLE AGEfront-end 3/3 3 3 177m[root@k8s-master ~]# kubectl get pod -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESfront-end-6b7b5c4bfc-48b8x 1/1 Running 0 177m 10.224.169.135 k8s-node2
访问测试:[root@k8s-master ~]# curl -Lk 10.224.169.135
If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.
For online documentation and support please refer to
cat front-end-svc.yamlapiVersion: v1kind: Servicemetadata: name: nginxspec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80[root@k8s-master ks]# kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEfront-end-svc ClusterIP 10.103.129.150
cat front-end-svc.yamlapiVersion: v1kind: Servicemetadata: name: nginxspec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80[root@k8s-master ks]# kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEfront-end-svc ClusterIP 10.103.129.150 If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.Welcome to nginx!
修改两处:
1.添加hostNetwork: true 意思是让控制器的namespace使用和宿主机一样的网络,既让访问宿主机80和443直接就是映射到容器里的这两个端口。
ingess控制器生成的配置
2.修改镜像为dockerhub上面的景象地址,然后apply创建一下。
[root@k8s-master ~]# kubectl apply -f ingress-controller.yaml
下面开始创建ingress规则
[root@k8s-master ks]# cat ingress.yaml apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: minimal-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: /spec: rules: - host: example.long.com #宿主机设置本地hosts解析后可以访问本地址 paths: - path: /hello pathType: Prefix backend: service: name: nginx port: number: 80 [root@k8s-master ks]# kubectl apply -f ingress.yaml
控制器生成的配置
[root@k8s-master ks]# kubectl exec -it nginx-ingress-controller-4mpfv -n ingress-nginx -- sh
以上配置说明我们的规则动态生成到配置中了。
[root@k8s-master ks]# kubectl get ingressWarning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 IngressNAME CLASS HOSTS ADDRESS PORTS AGEminimal-ingress
以下在宿主机客户端用浏览器进行测试,完成。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~