kubernetes云平台管理实战: 自动加载到负载均衡(七)

一、如何实现外界能访问

外界访问不了

1、启动svc

[root@k8s-master ~]# cat myweb-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30001
  selector:
    app: myweb
[root@k8s-master ~]# kubectl create -f myweb-svc.yaml
service "nginx" created

2、查看svc状态

[root@k8s-master ~]# kubectl get all
NAME       DESIRED   CURRENT   READY     AGE
rc/myweb   3         3         3         19m

NAME             CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
svc/kubernetes   10.254.0.1       <none>        443/TCP        22h
svc/nginx        10.254.205.175   <nodes>       80:30001/TCP   27s

NAME             READY     STATUS    RESTARTS   AGE
po/myweb-7m76h   1/1       Running   0          18m
po/myweb-kzq8c   1/1       Running   0          18m
po/myweb-mnf7x   1/1       Running   0          18m

3、被外界访问原理图

二、为什么是30001?

1、修改为3000看看是否正常?

[root@k8s-master ~]# vim myweb-svc.yaml
更改端口为:3000
[root@k8s-master ~]# kubectl delete svc/nginx
service "nginx" deleted
[root@k8s-master ~]# kubectl create -f myweb-svc.yaml
The Service "nginx" is invalid: spec.ports[0].nodePort: Invalid value: 3000:
provided port is not in the valid range. The range of valid ports is 30000-32767

2、端口更改为30001

[root@k8s-master ~]# vim myweb-svc.yaml
更改端口为:30001
[root@k8s-master ~]# kubectl create -f myweb-svc.yaml
service "nginx" created
[root@k8s-master ~]# kubectl get all
NAME       DESIRED   CURRENT   READY     AGE
rc/myweb   3         3         3         25m

NAME             CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
svc/kubernetes   10.254.0.1      <none>        443/TCP        22h
svc/nginx        10.254.145.15   <nodes>       80:30027/TCP   8s

NAME             READY     STATUS    RESTARTS   AGE
po/myweb-7m76h   1/1       Running   0          24m
po/myweb-kzq8c   1/1       Running   0          24m
po/myweb-mnf7x   1/1       Running   0          25m

默认不填写,自动分配30000-32767内任意一端口

三、自动加载到负载均衡里面

1、修改svc副本数为1

[root@k8s-master ~]# kubectl get pod -o wide
NAME          READY     STATUS    RESTARTS   AGE       IP            NODE
myweb-7m76h   1/1       Running   0          26m       172.16.10.2   k8s-node1
myweb-kzq8c   1/1       Running   0          26m       172.16.48.4   k8s-node2
myweb-mnf7x   1/1       Running   0          26m       172.16.48.2   k8s-node2

[root@k8s-master ~]# kubectl edit rc myweb
  replicas: 1
replicationcontroller "myweb" edited

[root@k8s-master ~]# kubectl get pod -o wide
NAME          READY     STATUS    RESTARTS   AGE       IP            NODE
myweb-mnf7x   1/1       Running   0          28m       172.16.48.2   k8s-node2
[root@k8s-master ~]# kubectl  describe svc nginx
Name:			nginx
Namespace:		default
Labels:			<none>
Selector:		app=myweb
Type:			NodePort
IP:			10.254.145.15
Port:			<unset>	80/TCP
NodePort:		<unset>	30027/TCP
Endpoints:		172.16.48.2:80
Session Affinity:	None
No events.

2、修改svc副本数为5

[root@k8s-master ~]# kubectl edit rc myweb
  replicas: 5
replicationcontroller "myweb" edited
[root@k8s-master ~]# kubectl  describe svc nginx
Name:			nginx
Namespace:		default
Labels:			<none>
Selector:		app=myweb
Type:			NodePort
IP:			10.254.145.15
Port:			<unset>	80/TCP
NodePort:		<unset>	30027/TCP
Endpoints:		172.16.10.2:80,172.16.10.3:80,172.16.48.2:80 + 1 more...
Session Affinity:	None
No events.
[root@k8s-master ~]# kubectl get pod -o wide
NAME          READY     STATUS    RESTARTS   AGE       IP            NODE
myweb-415zs   1/1       Running   0          9s        172.16.48.3   k8s-node2
myweb-7bw5f   1/1       Running   0          9s        172.16.10.3   k8s-node1
myweb-7kzh2   1/1       Running   0          9s        172.16.48.4   k8s-node2
myweb-j45xb   1/1       Running   0          9s        172.16.10.2   k8s-node1
myweb-mnf7x   1/1       Running   0          30m       172.16.48.2   k8s-node2

四、上网测试截图

1、node1 web截图

2、node2 web截图

原文地址:https://www.cnblogs.com/luoahong/p/10300385.html

时间: 2024-09-30 10:28:29

kubernetes云平台管理实战: 自动加载到负载均衡(七)的相关文章

kubernetes云平台管理实战: 服务发现和负载均衡(五)

一.rc控制器常用命令 1.rc控制器信息查看 [root@k8s-master ~]# kubectl get replicationcontroller NAME DESIRED CURRENT READY AGE myweb 3 3 3 3m [root@k8s-master ~]# kubectl get rc NAME DESIRED CURRENT READY AGE myweb 3 3 3 5m 2.删除rc [root@k8s-master ~]# kubectl delete

kubernetes云平台管理实战:HPA水平自动伸缩(十一)

一.自动伸缩 1.启动 [root@k8s-master ~]# kubectl autoscale deployment nginx-deployment --max=8 --min=2 --cpu-percent=80 deployment "nginx-deployment" autoscaled 2.查看创建 [root@k8s-master ~]# kubectl get all NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE de

kubernetes云平台管理实战:deployment通过标签管理pod(十)

一.kubectl run命令拓展 1.RC创建 [root@k8s-master ~]# kubectl run web --generator=run/v1 --image=10.0.128.0:5000/nginx:1.13 --replicas=3 replicationcontroller "web" created 2.deployment创建 [root@k8s-master ~]# kubectl run web --image=10.0.128.0:5000/ngin

kubernetes云平台管理实战: 高级资源deployment-滚动升级(八)

一.通过文件创建deployment 1.创建deployment文件 [root@k8s-master ~]# cat nginx_deploy.yml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx im

kubernetes云平台管理实战: 滚动升级秒级回滚(六)

一.nginx保证有两个版本 1.查看当前容器运行nginx版本 [root@k8s-master ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE myweb-7w38b 1/1 Running 0 4h 172.16.10.4 k8s-node1 myweb-btflm 1/1 Running 0 4h 172.16.48.4 k8s-node2 myweb-cbt47 1/1 Running 0 4h 17

kubernetes云平台管理实战:如何创建deployment更好(九)

一.文件创建带--record 1.文件 [root@k8s-master ~]# cat nginx_deploy.yml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: 10.0.128.0

基于 Koa平台Node.js开发的KoaHub.js的控制器,模型,帮助方法自动加载

koahub-loader koahub-loader是基于 Koa平台Node.js开发的KoaHub.js的koahub-loader控制器,模型,帮助方法自动加载 koahub loader Installation $ npm install koahub-loader Use with koa // 1.model loader var model = loader([ {      root: './app/model',      suffix: '.model.js' }, { 

openStack 云平台管理节点管理网口流量非常大 出现丢包严重 终端总是时常中断问题调试及当前测试较有效方案

tuning for Data Transfer hosts connected at speeds of 1Gbps or higher <一.本次OpenStack系统调试简单过程简单记录> 1,dmesg 日志,丢包问题关键原因定位; [101231.909932] net_ratelimit: 85 callbacks suppressed 2,ethstatus -i p5p1 实时追踪网口TX/RX状态; 3,具体内核等相关参数调整 # recommended default co

__利用PHP的debug_backtrace函数,实现PHP文件权限管理、动态加载

利用PHP的debug_backtrace函数,实现PHP文件权限管理.动态加载 简述 可能大家都知道,php中有一个函数叫debug_backtrace,它可以回溯跟踪函数的调用信息,可以说是一个调试利器. 好,来复习一下.view source?01    one();02     03    function one() {04        two();05    }06     07    function two() {08        three();09    }10