本文共 4981 字,大约阅读时间需要 16 分钟。
简述
Deployment为Pod和ReplicaSet提供了一个声明式定义(declarative)方法,用来替代以前的ReplicationController来方便的管理应用。典型的应用场景包括:
replication controller与deployment的区别
replication controllerDeployment
Deployment同样为Kubernetes的一个核心内容,主要职责同样是为了保证pod的数量和健康,90%的功能与Replication Controller完全一样,可以看做新一代的Replication Controller。但是,它又具备了Replication Controller之外的新特性: Replication Controller全部功能:Deployment继承了上面描述的Replication Controller全部功能。
导入镜像
docker load < kubernetes-dashboard-amd64-v1.5.1.tar
docker load < pause-amd64-3.0.tar
测试一个nginx-deployment.yaml
kind: DeploymentapiVersion: extensions/v1beta1metadata: name: nginx-deploymentspec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
执行nginx-deployment.yaml
kubectl create -f nginx-deployment.yaml
检查状态
kubectl get pod
查看容器IP
kubectl get pods -o yaml -l app=nginx | grep podIP
deployment滚动升级
kubectl set image deployment/nginx-deployment nginx=192.168.2.51:5000/k8images/nginx:v1注:
nginx-deployment 回滚
kubectl rollout undo deployment/nginx实现自动pod伸缩
kubectl autoscale deployment nginx-deployment --min=2 --max=6 --cpu-percent=80注:当容器cpu使用了达到80%的时候 自动伸缩, 分片数量最小2个 最大6个
查看horizontalpodautoscalers
kubectl get horizontalpodautoscalers
在线修改horizontalpodautoscalers配置
kubectl edit horizontalpodautoscalers nginx
创建nginx-service
因为pod的IP是不固定的所以创建一个service,他的IP是固定的
apiVersion: v1kind: Servicemetadata: name: nginx-demo labels: app: nginxspec: ports: - port: 80 protocol: TCP selector: app: nginx
注:app: nginx = deployment配置文件中 labels标签下app名称
查看状态
kubectl get service
创建kubernetes-dashboard
# Copyright 2015 Google Inc. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.# Configuration to deploy release version of the Dashboard UI.## Example usage: kubectl create -fkind: DeploymentapiVersion: extensions/v1beta1metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-systemspec: replicas: 1 selector: matchLabels: app: kubernetes-dashboard template: metadata: labels: app: kubernetes-dashboard # Comment the following annotation if Dashboard must not be deployed on master annotations: scheduler.alpha.kubernetes.io/tolerations: | [ { "key": "dedicated", "operator": "Equal", "value": "master", "effect": "NoSchedule" } ] spec: containers: - name: kubernetes-dashboard image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.5.1 ports: - containerPort: 9090 protocol: TCP args: # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. - --apiserver-host=http://192.168.56.11:8080 livenessProbe: httpGet: path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30---kind: ServiceapiVersion: v1metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-systemspec: type: NodePort ports: - port: 80 targetPort: 9090 selector: app: kubernetes-dashboard
kubectl create -f kubernetes-dashboard.yaml
查看deployment运行
kubectl get deployment --namespace=kube-system
查看pod
kubectl get pod --namespace=kube-system
查看service
浏览器访问
转载地址:http://emepb.baihongyu.com/