1. 部署应用流程
制作镜像[dockerfile] –> 使用控制器部署镜像[deployment] –>对外暴露应用[service] –>日常运维
2. 获取nginx 镜像
#docker pull nginx
#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 87a94228f133 2 weeks ago 133MB
3.使用控制器部署镜像
#kubectl create deployment nginx --image=nginx --replicas=3
deployment.apps/nginx created
# kubectl get deploy,pods
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx 3/3 3 3 2m55s
NAME READY STATUS RESTARTS AGE
pod/nginx-6799fc88d8-2qwfq 1/1 Running 0 2m55s
pod/nginx-6799fc88d8-72wkn 1/1 Running 0 2m55s
pod/nginx-6799fc88d8-vqkhw 1/1 Running 0 2m55s
4.创建一个service 将应用暴露到外网
# kubectl expose deployment.apps/nginx --port=80 --target-port=80 --type=NodePort
service/nginx exposed
# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.1.0.1 <none> 443/TCP 27h
nginx NodePort 10.1.28.92 <none> 80:31162/TCP 23s
5.验证 http://47.89.217.69:31162/
上次更新时间 13 3 月, 2023 at 09:59 上午