K8S学习-deployment创建容器

通过deployment创建容器

#创建一个deployment文件,下面是创建示例
[root@master1 test_yaml]# kubectl create deployment --help
Create a deployment with the specified name.

Aliases:
deployment, deploy

Examples:
  # Create a deployment named my-dep that runs the busybox image
  kubectl create deployment my-dep --image=busybox

  # Create a deployment with a command
  kubectl create deployment my-dep --image=busybox -- date

  # Create a deployment named my-dep that runs the nginx image with 3 replicas
  kubectl create deployment my-dep --image=nginx --replicas=3

  # Create a deployment named my-dep that runs the busybox image and expose port 5701
  kubectl create deployment my-dep --image=busybox --port=5701

Options:
      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
      --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
sent, without sending it. If server strategy, submit server-side request without persisting the resource.
      --field-manager='kubectl-create': Name of the manager used to track field ownership.
      --image=[]: Image names to run.
  -o, --output='': Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.
      --port=-1: The port that this container exposes.
  -r, --replicas=1: Number of replicas to create. Default is 1.
      --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the
annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
      --show-managed-fields=false: If true, keep the managedFields when printing objects in JSON or YAML format.
      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
      --validate=true: If true, use a schema to validate the input before sending it

Usage:
  kubectl create deployment NAME --image=image -- [COMMAND] [args...] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

#创建一个nginx的deployment,指定镜像是nginx:1.7.9,启动一个容器实例
[root@master1 test_yaml]#  kubectl create deployment nginx-deployment --image=nginx:1.7.9 --replicas=1
deployment.apps/nginx-deployment created
[root@master1 test_yaml]# kubectl get pods -A -o wide
NAMESPACE     NAME                                       READY   STATUS    RESTARTS      AGE   IP               NODE        NOMINATED NODE   READINESS GATES
default       nginx-deployment-84b896cf65-dfw49          1/1     Running   0             29s   10.10.36.92      k8s-node1   <none>
#查看创建的deployment文件的详细信息
[root@master1 test_yaml]# kubectl get deployment -n default
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   1/1     1            1           60s
[root@master1 test_yaml]# kubectl get deployment nginx-deployment -n default -o yaml
apiVersion: apps/v1                                         #deployment的API版本
kind: Deployment                                            #资源类型为deployment
metadata:                                                   #元信息描述
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2023-10-16T13:34:44Z"
  generation: 1
  labels:                                                  #标签
    app: nginx-deployment                                  #标签的具体key和value
  name: nginx-deployment                                   #deployment的名字
  namespace: default                                       #所在的命名空间
  resourceVersion: "54079"
  uid: 04f49451-6cea-4754-9ba6-9231643da1b9
spec:
  progressDeadlineSeconds: 600
  replicas: 1                                              #指定副本数量
  revisionHistoryLimit: 10                                 #进行滚动更新后保留的历史版本数
  selector:                                                #选择器,用于找到匹配的RS
    matchLabels:                                           #按照标签匹配
      app: nginx-deployment                                #匹配的标签
  strategy:                                                #更新策略
    rollingUpdate:                                         #滚动更新
      maxSurge: 25%                                        #更新比例
      maxUnavailable: 25%                                  #更新个数限制
    type: RollingUpdate                                    #更新类型  滚动更新
  template:                                                #pod模板
    metadata:                                              #pod的元信息
      creationTimestamp: null
      labels:                                              #pod的标签
        app: nginx-deployment
    spec:                                                  #pod期望信息
      containers:                                          #pod容器
      - image: nginx:1.7.9                                 #pod创建启动拉取的镜像
        imagePullPolicy: IfNotPresent                      #拉取策略
        name: nginx                                        #容器的名称
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always                               #重启策略
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30                   #删除容器最多宽限多长时间
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: "2023-10-16T13:34:46Z"
    lastUpdateTime: "2023-10-16T13:34:46Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2023-10-16T13:34:44Z"
    lastUpdateTime: "2023-10-16T13:34:46Z"
    message: ReplicaSet "nginx-deployment-84b896cf65" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1

#容器的名称规则先是deployment,然后是replicaset,其次是pods这样一层嵌套关系
[root@master1 test_yaml]# kubectl get deployment
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   1/1     1            1           6m24s
[root@master1 test_yaml]# kubectl get replicaset
NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-84b896cf65   1         1         1       6m31s
[root@master1 test_yaml]# kubectl get pods
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-84b896cf65-dfw49   1/1     Running   0          6m38s


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值