pod controller service 简图
controller讲解
kubectl create deployment web --image=nginx --dry-run -o yaml > web.yaml
--dry-run is deprecated and can be replaced with --dry-run=client.
kubectl apply -f web.yaml
controller 详细全解析
依然是那2个指令,创建 和 暴露
- controller对应的注解是: deployment
$ kubectl create deployment nginx --image=nginx
$ kubectl expose deployment nginx --port=80 --type=NodePort
kubectl expose --help
kubectl create deployment web --image=nginx --dry-run -o yaml > web.yaml
kubectl expose deployment web --port=80 --type=NodePort --target-port=80 --name=web1 --dry-run -o yaml > web1.yaml
kubectl apply -f web1.yaml
kubectl get pods,svc
kubectl delete deployment web
kubectl delete svc web
kubectl delete pod web
replicas
kubectl scale deployment web --replicas=5
或者修改create命令创建的文件中:
spec:
replicas:2
spec:
containers:
- image: nginx:1.14
升级版本 回滚 和 弹性伸缩
kubectl set image deployment web nginx=nginx:1.15
在node上 docker iamges 也可看效果
kubectl rollout status deployment web
deployment "web" successfully rolled out
kubectl rollout history deployment web
kubectl rollout undo deployment web
kubectl rollout undo deployment web --to-revision=2
kubetctl scale deployment web --replicas=10
service
- 先访问的是 service
- 通过 controller 创建pod ???
kubectl expose --help
--type='': Type for this service:
ClusterIP,
NodePort,
LoadBalancer, or ExternalName.
Default is 'ClusterIP'
[root@k8snode2 ~]
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web NodePort 10.99.117.190 <none> 80:30152/TCP 43m
|