标签:ipvs ons update rev host bec 新版本 ready 0.11
[root@master ~]# kubectl run myapp --image=ikubernetes/myapp:v1 --port=80 --replicas=1
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/myapp created
[root@master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
client 1/1 Running 0 7d18h 10.244.2.3 node2 <none> <none>
myapp-55b9654fbb-psgmb 1/1 Running 0 3s 10.244.1.9 node1 <none> <none>
nginx-deploy-54b5756c7-btwm4 1/1 Running 0 45m 10.244.2.6 node2 <none> <none>
nginx-deploy-54b5756c7-s4fml 1/1 Running 0 45m 10.244.1.6 node1 <none> <none>
创建完成后,它在default名称空间中创建了一个名为myapp的Deploument控制器对象,并且它基于指定的镜像文件创建了一个Pod对象
可以使用kubectl run -h
获取更多用途
[root@master ~]# kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
myapp 1/1 1 1 108m
nginx-deploy 2/2 2 2 3h18m
READY
当前已有pod副本数量/期望数量
UP-TO-DATE
更新到最新版本定义的pod对象的副本数量,在控制器的滚动更新模式下,它表示已经完成版本更细你的pod对象的副本数量
AVAILABLE
当前处于可用状态的pod副本的数量
AGE
Pod存在的时长
kubectl describe
kubectl logs
kubectl exec
一个service对象可视作通过标签选择器过滤一组pod对象,并能为此组pod对象监听套接字提供端口代理和调度服务
[root@master ~]# kubectl expose deployment/myapp --type="NodePort" --port=80 --name=myapp-svc
service/myapp-svc exposed
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11d
myapp-svc NodePort 10.100.110.97 <none> 80:31590/TCP 4s
nginx-svc ClusterIP 10.102.230.186 <none> 80/TCP 161m
[root@master ~]# curl 10.100.110.97
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
expose
暴露
deployment/myapp
根据标签选择一组pod
--type
指定service的类型
++Service创建时,其名称和ClusterIP会由CoreDNS附件动态添加至名称解析库中,因此名称解析服务在对象创建后即可直接使用++
++ClusterIP为service的地址,它是一个虚拟ip,并没有配置在集群中任何主机的任何接口上,但是每个node之上的kube-proxy都会为CluserIP所在的网络创建用于转发的iptables或者ipvs规则,用户可以在集群外部任何浏览器请求集群任一节点的相关端口进行访问测试++
[root@master ~]# kubectl describe service myapp-svc
Name: myapp-svc
Namespace: default
Labels: run=myapp
Annotations: <none>
Selector: run=myapp
Type: NodePort
IP: 10.100.110.97
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 31590/TCP
Endpoints: 10.244.1.9:80
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
Selector
当前service对象使用的标签选择器,用于选择关联的pod对象
Type
service类型,可以是ClusterIP,NodePort,LoadBalancer等之一
Port
暴露端口,当前service用于接受并响应的请求端口
TargetPort
容器中用于暴露的目标端口,由service port请求至此端口
NodePort
当前service的NodePort,它是否存在有效值和Type字段中的类型相关
Endpoints
后端端点,即被当前service的Select选择的所有pod的IP和PORT
Session Affinity
是否启用会话粘性
EXternal Traffic Policy
外部流量的调度策略
[root@master ~]# kubectl scale deployment/myapp --replicas=3
deployment.extensions/myapp scaled
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
client 1/1 Running 0 7d21h
myapp-55b9654fbb-87fdz 1/1 Running 0 11s
myapp-55b9654fbb-psgmb 1/1 Running 0 169m
myapp-55b9654fbb-tntp4 1/1 Running 0 11s
nginx-deploy-54b5756c7-btwm4 1/1 Running 0 3h35m
nginx-deploy-54b5756c7-s4fml 1/1 Running 0 3h35m
完成扩容后,查看deployment和service详细信息
[root@master ~]# kubectl describe deployment -l run=myapp
Name: myapp
Namespace: default
CreationTimestamp: Tue, 22 Jan 2019 11:55:25 +0800
Labels: run=myapp
Annotations: deployment.kubernetes.io/revision: 1
Selector: run=myapp
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: run=myapp
Containers:
myapp:
Image: ikubernetes/myapp:v1
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: myapp-55b9654fbb (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 81s deployment-controller Scaled up replica set myapp-55b9654fbb to 3
# 显示已经完成扩容
[root@master ~]# kubectl describe service/myapp-svc
Name: myapp-svc
Namespace: default
Labels: run=myapp
Annotations: <none>
Selector: run=myapp
Type: NodePort
IP: 10.100.110.97
Port: <unset> 80/TCP
TargetPort: 80/TCP
NodePort: <unset> 31590/TCP
Endpoints: 10.244.1.10:80,10.244.1.9:80,10.244.2.8:80
# 创建的service资源对象后端端点也已经通过标签选择器自动扩展到了这3个pod对象相关的端点
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
成功创建在k8s上的对象也成为活动对象,其配置信息由API Service保存于集群状态存储系统etcd中,而运行 kubectl edit
命令可调用默认编辑器对活动对象的可配置对象进行编辑。
有些命令是kubectl edit
命令某一部分功能的二次封装 ,例如 kubectl scale
命令不过是专用于修改资源对象的replicas属性值,它也同样作用于活动对象,这样就很容易理解了。
删除受控制器控制的pods
[root@master ~]# kubectl delete deployment myapp
deployment.extensions "myapp" deleted
kubernetes命令式容器应用编排/部署应用/探查应用详情/部署service对象/扩缩容/修改删除对象
标签:ipvs ons update rev host bec 新版本 ready 0.11
原文地址:https://www.cnblogs.com/mumengyun/p/10304019.html