1. 创建一个deployment
(1)新建kubeserve-deployment.yaml文件,内容如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubeserve
spec:
replicas: 3
selector:
matchLabels:
app: kubeserve
template:
metadata:
name: kubeserve
labels:
app: kubeserve
spec:
containers:
- image: linuxacademycontent/kubeserve:v1
name: app
(2)用kubectl执行这个yaml文件,创建deployment。根据yaml文件可知,创建的deployment的名字为kubeserve。根据yaml中的replicas的数字是3,知道生成了3个pod。
kubectl apply -f kubeserve-deployment.yaml --record
(3)检查deployment是否成功了
kubectl rollout status deployments kubeserve
(4)检查应用application的版本是否正确
kubectl describe deployment kubeserve
2. 扩容application,实现高可用(Scale up the application to create high availability)
(1)扩容到5个pod
kubectl scale deployment kubeserve --replicas=5
(2)查看pod情况
kubectl get pods
3. 创建一个service,让用户可以访问这个application
(1)创建service
kubectl expose deployment kubeserve --port 80 --target-port 80 --type NodePort
(2)查看service和集群cluster的ip
kubectl get services
(3)访问ip,因为http默认端口就是80,可以省略写80
curl http://<ip-address-of-the-service>
4. 升级应用(rolling update of the application)
(1)创建一个循环,不断访问url,即查看版本号的实时变化
while true; do curl http://<ip-address-of-the-service>; done
(2)升级,步骤(1)现在也同时在运行呢。
kubectl set image deployments/kubeserve app=linuxacademycontent/kubeserve:v2 --v 6
(3)查看所有运行着的pod
kubectl get pods
(4)查看rollout history
kubectl rollout history deployment kubeserve