[root@devops-101 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION devops-101 Ready master 7h v1.11.1 devops-102 Ready <none> 6h v1.11.1
2. 命令行方式创建部署
创建Tomcat部署,设置两个副本。
1 2 3 4 5 6 7 8 9
$ kubectl run docker.io/tomcat --replicas=2 --labels="app=tomcat" --image=docker.io/tomcat --port=8080 deployment.apps/tomcat created [root@devops-101 ~]# kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE tomcat 2 2 2 2 6m [root@devops-101 ~]# kubectl get pods NAME READY STATUS RESTARTS AGE tomcat-858b8c476d-vnm98 1/1 Running 0 6m tomcat-858b8c476d-xl5xl 1/1 Running 0 6m
[root@devops-101 ~]# kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8h tomcat NodePort 10.98.152.28 <none> 8080:32050/TCP 7s
apiVersion:v1 kind:Pod metadata:#元数据信息 name:tomcat-c#kubectl get pods 和 登陆容器显示的名字 labels:#标签,可以作为查询条件 kubectl get pods -l app=tomcat node=devops-103 spec:#规格 containers:#容器 -name:tomcat#容器名称 image:docker.io/tomcat#使用的镜像 ports: -containerPort:8080 env:#设置env,登陆到容器中查看环境变量, DEME_GREETING 的值是 "hello from the enviroment" -name:GREETING value:"hello from the environment"
然后创建Pod。
1 2 3 4 5 6 7
[root@devops-101 ~]# kubectl create -f tomcat.yaml pod/tomcat-ccb created [root@devops-101 ~]# kubectl get pods NAME READY STATUS RESTARTS AGE tomcat-858b8c476d-vnm98 1/1 Running 2 21h tomcat-858b8c476d-xl5xl 1/1 Running 3 21h tomcat-ccb 1/1 Running 0 34s
4. 扩容部署
在扩容之前,我把devops-102节点也加入到集群中。
1 2 3 4 5
[root@devops-101 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION devops-101 Ready master 9h v1.11.1 devops-102 Ready <none> 8h v1.11.1 devops-103 Ready <none> 7h v1.11.1