集成环境部署

  1. # API 版本号
  2. apiVersion: extensions/v1beta1
  3. # 类型,如:Pod/ReplicationController/Deployment/Service/Ingress
  4. kind: Deployment
  5. # 元数据
  6. metadata:
  7. # Kind 的名称
  8. name: nginx-app
  9. spec:
  10. # 部署的实例数量
  11. replicas: 2
  12. template:
  13. metadata:
  14. labels:
  15. # 容器标签的名字,发布 Service 时,selector 需要和这里对应
  16. name: nginx
  17. spec:
  18. # 配置容器,数组类型,说明可以配置多个容器
  19. containers:
  20. # 容器名称
  21. - name: nginx
  22. # 容器镜像
  23. image: nginx:1.17
  24. # 只有镜像不存在时,才会进行镜像拉取
  25. imagePullPolicy: IfNotPresent
  26. # 暴露端口
  27. ports:
  28. # Pod 端口
  29. - containerPort: 80
  30. ---
  31. # API 版本号
  32. apiVersion: v1
  33. # 类型,如:Pod/ReplicationController/Deployment/Service/Ingress
  34. kind: Service
  35. # 元数据
  36. metadata:
  37. # Kind 的名称
  38. name: nginx-http
  39. spec:
  40. # 暴露端口
  41. ports:
  42. ## Service 暴露的端口
  43. - port: 80
  44. ## Pod 上的端口,这里是将 Service 暴露的端口转发到 Pod 端口上
  45. targetPort: 80
  46. # 类型
  47. type: LoadBalancer
  48. # 标签选择器
  49. selector:
  50. # 需要和上面部署的 Deployment 标签名对应
  51. name: nginx
# 部署
kubectl create -f nginx.yml
# 删除
kubectl delete -f nginx.yml

验证是否生效

查看 Pod 列表

kubectl get pods

NAME                         READY   STATUS    RESTARTS   AGE
nginx-app-7cbc957b87-p24px   1/1     Running   0          3s
nginx-app-7cbc957b87-tmjr4   1/1     Running   0          3s

查看 Deployment 列表

kubectl get deployment

NAME        READY   UP-TO-DATE   AVAILABLE   AGE
nginx-app   2/2     2            2           14s

查看 Service 列表

kubectl get service

NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP        3h47m
nginx-http   LoadBalancer   10.104.118.232   <pending>     80:32264/TCP   23s

查看 Service 详情

kubectl describe service nginx-http

Name:                     nginx-http
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 name=nginx
Type:                     LoadBalancer
IP:                       10.104.118.232
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  32264/TCP
Endpoints:                10.244.140.95:80,10.244.141.226:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>