集成环境部署
# API 版本号apiVersion: extensions/v1beta1# 类型,如:Pod/ReplicationController/Deployment/Service/Ingresskind: Deployment# 元数据metadata: # Kind 的名称 name: nginx-appspec: # 部署的实例数量 replicas: 2 template: metadata: labels: # 容器标签的名字,发布 Service 时,selector 需要和这里对应 name: nginx spec: # 配置容器,数组类型,说明可以配置多个容器 containers: # 容器名称 - name: nginx # 容器镜像 image: nginx:1.17 # 只有镜像不存在时,才会进行镜像拉取 imagePullPolicy: IfNotPresent # 暴露端口 ports: # Pod 端口 - containerPort: 80---# API 版本号apiVersion: v1# 类型,如:Pod/ReplicationController/Deployment/Service/Ingresskind: Service# 元数据metadata: # Kind 的名称 name: nginx-httpspec: # 暴露端口 ports: ## Service 暴露的端口 - port: 80 ## Pod 上的端口,这里是将 Service 暴露的端口转发到 Pod 端口上 targetPort: 80 # 类型 type: LoadBalancer # 标签选择器 selector: # 需要和上面部署的 Deployment 标签名对应 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>