K8S基础:服务网络service/ingress

网友投稿 272 2022-10-21

K8S基础:服务网络service/ingress

Service:Pod的服务发现与负载均衡

1、配置现有deployment的service(cluster IP)

[root@master server]# kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE mynginx 3/3 3 3 26m [root@master server]# kubectl expose deploy/mynginx --port=8000 --target-port=80 —type=ClusterIP service/mynginx exposed [root@master server]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.233.0.1 443/TCP 23h mynginx ClusterIP 10.233.24.235 8000/TCP 7s #访问svc的ip测试 [root@master server]# curl 10.233.24.235:8000 Welcome to nginx! Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

[root@master server]# kubectl get pod --show-labels NAME READY STATUS RESTARTS AGE LABELS mynginx-5b686ccd46-4cwr8 1/1 Running 0 35m app=mynginx,pod-template-hash=5b686ccd46 mynginx-5b686ccd46-r82j6 1/1 Running 0 36m app=mynginx,pod-template-hash=5b686ccd46 mynginx-5b686ccd46-zdfrb 1/1 Running 0 35m app=mynginx,pod-template-hash=5b686ccd46 #通过域名访问(在容器内部访问),访问格式:${app}.${namespace}.svc:${svc port} root@mynginx-5b686ccd46-4cwr8:/# curl mynginx.default.svc:8000 Welcome to nginx! Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

root@mynginx-5b686ccd46-4cwr8:/#

2、配置现有deployment的service(NodePort IP)

#删除clusterIP模式的svc [root@master server]# kubectl delete svc mynginx service "mynginx” deleted #创建新的svc,Nodeport模式 [root@master server]# kubectl expose deploy/mynginx --port=8000 --target-port=80 --type=NodePort service/mynginx exposed [root@master server]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.233.0.1 443/TCP 23h mynginx NodePort 10.233.28.231 8000:32121/TCP 9s [root@master server]# #公网访问:主机IP+port [root@master server]# curl http://139.198.104.152:32121/ Welcome to nginx! Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

[root@master server]#

Ingress:service的统一网关入口

1、部署安装Ingress

#yaml部署安装Ingress [root@master server]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.2/deploy/static/provider/cloud/deploy.yaml namespace/ingress-nginx created serviceaccount/ingress-nginx created serviceaccount/ingress-nginx-admission created role.rbac.authorization.k8s.io/ingress-nginx created role.rbac.authorization.k8s.io/ingress-nginx-admission created clusterrole.rbac.authorization.k8s.io/ingress-nginx created clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created rolebinding.rbac.authorization.k8s.io/ingress-nginx created rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created configmap/ingress-nginx-controller created service/ingress-nginx-controller created service/ingress-nginx-controller-admission created deployment.apps/ingress-nginx-controller created job.batch/ingress-nginx-admission-create created job.batch/ingress-nginx-admission-patch created ingressclass.networking.k8s.io/nginx created validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created #查看ingress创建状态 [root@master server]# kubectl get pod -A NAMESPACE NAME READY STATUS RESTARTS AGE ingress-nginx ingress-nginx-admission-create-pmgsz 0/1 ImagePullBackOff 0 76s ingress-nginx ingress-nginx-admission-patch-sz7r7 0/1 ImagePullBackOff 0 76s ingress-nginx ingress-nginx-controller-cb87575f5-8rccx 0/1 ContainerCreating 0 76s

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java并发编程之原子性
下一篇:K8S基础:通过多种方式管理Pod
相关文章

 发表评论

暂时没有评论,来抢沙发吧~