一、控制器部署镜像Deployment
### --- 创建一个Pod之生成yaml文件
[root@k8s-master1 ~]# kubectl create deployment javademo1 --image=registry.cn-hangzhou.aliyuncs.com/docker-yanqi/java-project-01:1.0.0 --dry-run -o yaml > javademo1.yaml
[root@k8s-master1 ~]# ls
javademo1.yaml
### --- 创建Javademo1的pod
[root@k8s-master1 ~]# kubectl apply -f javademo1.yaml
deployment.apps/javademo1 created
[root@k8s-master1 ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
javademo1-659c9d6665-9r2v4 1/1 Running 0 43s
[root@k8s-master1 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
javademo1-659c9d6665-9r2v4 1/1 Running 0 61s 10.244.2.3 k8s-node1 <none> <none>
### --- 扩容添加几个副本
[root@k8s-master1 ~]# kubectl scale deployment javademo1 --replicas=3
deployment.apps/javademo1 scaled
[root@k8s-master1 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
javademo1-659c9d6665-9r2v4 1/1 Running 0 4m40s 10.244.2.3 k8s-node1 <none> <none>
javademo1-659c9d6665-cqwnm 1/1 Running 0 31s 10.244.2.4 k8s-node1 <none> <none>
javademo1-659c9d6665-snkbm 1/1 Running 0 31s 10.244.2.5 k8s-node1 <none> <none>
二、对外暴露应用service Ingress
### --- 对外暴露端口
[root@k8s-master1 ~]# kubectl expose deployment javademo1 --port=8111 --target-port=8111 --type=NodePort
service/javademo1 exposed
[root@k8s-master1 ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
javademo1 NodePort 10.1.183.81 <none> 8111:30938/TCP 24s
### --- 对外暴露的端口是30938,通过任何一个节点+对外暴露端口都可以输出内容
~~~ http://10.10.10.11:30938/user 输出:hello
~~~ http://10.10.10.12:30938/user 输出:hello
~~~ http://10.10.10.13:30938/user 输出:hello
~~~ http://10.10.10.15:30938/user 输出:hello # vip输出