Docker Kubernetes YAML文件建立容器nginx
經過建立Deployment來管理pods從而建立容器。它會同時建立容器、pod、以及Deployment !vim
環境:api
建立yaml文件app
vim nginx-deployment.yaml
apiVersion: apps/v1beta2 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.9 ports: - containerPort: 80
# 指定api版本 apiVersion: apps/v1beta2 # 指定須要建立的資源對象 kind: Deployment # 源數據、能夠寫name,命名空間,對象標籤 metadata: # 指定建立對象名稱 name: nginx-deployment # spec 描述pod相關信息 spec: # pod 副本數,默認1 replicas: 3 # pod 標籤選擇器 selector: # pod 匹配標籤字段 matchLabels: # pod 匹配app值爲nginx app: nginx # 容器 描述pod具體信息 template: # 容器 指定標籤 metadata: # 容器 匹配標籤字段 labels: # 容器 匹配值aap值爲nginx app: nginx # 容器信描述信息 spec: # 指定容器信息 containers: # 指定容器名稱 - name: nginx # 指定鏡像名稱 image: nginx:1.10 # 暴露容器端口 ports: # 指定暴露容器端口 - containerPort: 80
建立deployment資源ide
kubectl create -f nginx-deployment.yaml
命令:kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-deployment 3 3 3 3 1m
命令:kubectl get replicaset
NAME DESIRED CURRENT READY AGE
nginx-deployment-845cfc7fb9 3 3 3 4m
命令:kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deployment-845cfc7fb9-j2xcv 1/1 Running 0 5m nginx-deployment-845cfc7fb9-jfq5b 1/1 Running 0 5m nginx-deployment-845cfc7fb9-sbrsp 1/1 Running 0 5m