Kubernetes Services && Update

2018年8月16日16:37:23 发表评论 2,809 ℃

运行三个httpd镜像

Kubernetes Services && Update

创建service

Kubernetes Services && Update

① v1 是 Service 的 apiVersion。

② 指明当前资源的类型为 Service。

③ Service 的名字为 httpd-svc。

④ selector 指明挑选那些 label 为 run: httpd 的 Pod 作为 Service 的后端。

⑤ 将 Service 的 8080 端口映射到 Pod 的 80 端口,使用 TCP 协议。

  kubectl describe service httpd-svc  #查看httpd-svc与Pod的对应关系

iptables 将访问 Service 的流量转发到后端 Pod,而且使用类似轮询的负载均衡策略。

在kube-public中部署service httpds-svc

Kubernetes Services && Update

通过namespace: kube-public指定资源所属的namespace。多个资源可以在一个YAML文件中定义,用 --- 分割。

外网访问Service

ClusterIP 

Service 通过 Cluster 内部的 IP 对外提供服务,只有 Cluster 内的节点和 Pod 可访问,这是默认的 Service 类型,前面实验中的 Service 都是 ClusterIP。

NodePort 

Service 通过 Cluster 节点的静态端口对外提供服务。Cluster 外部可以通过 <NodeIP>:<NodePort> 访问 Service。

LoadBalancer 

Service 利用 cloud provider 特有的 load balancer 对外提供服务,cloud provider 负责将 load balancer 的流量导向 Service。目前支持的 cloud provider 有 GCP、AWS、Azur 等。

使用Nodeport方式

Kubernetes Services && Update

Kubernetes Services && Update

PORT(S) 为 8080:30651。8080 是 ClusterIP 监听的端口,30651则是节点上监听的端口。Kubernetes 会从 30000-32767 中分配一个可用的端口,每个节点都会监听此端口并将请求转发给 Service。

nodePort指定分配的端口

Kubernetes Services && Update

nodePort 是节点上监听的端口。

port 是 ClusterIP 上监听的端口。

targetPort 是 Pod 监听的端口。

版本回滚

默认配置下,Kubernetes 只会保留最近的几个 revision,可以在 Deployment 配置文件中通过 revisionHistoryLimit 属性增加 revision 数量。

Kubernetes Services && Update

 kubectl apply -f httpd.v1.yml --record

--record 的作用是将当前命令记录到 revision 记录中,这样我们就可以知道每个 revison 对应的是哪个配置文件。

kubectl rollout history deployment httpd 查看revision历史记录

Kubernetes Services && Update

kubectl rollout undo deployment httpd --to-revision=1 #回滚到版本1

【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: