• 17.Kubernetes深入Pod


    本节将对kubernetes如何发布和管理应用进行说明和示例,主要包括Pod和容器的使用、Pod的控制和调度、应用配置管理等内容。

    1.Pod定义详解

    yaml格式的Pod定义文件的完整内容:

    apiVersion: v1
    kind: Pod
    metadata:
      name: string
      namespace: string
      labels:
        - name: string
      annotations:
        - name: string
    spec:
      containers:
      - name: string
        image: string
        imagePullPolicy: [Always | Never | IfNotPresent]
        command: [string]
        args: [string]
        workingDir: string
        volumeMounts:
        - name: string
          mountPath: string
          readOnly: boolean
        ports:
        - name: string
          containerPort: int
          hostPort: ing
          protocol: string
        env:
        - name: string
          value: string
        resources:
          limits:
            cpu: string
            memory: string
          requests:
            cpu: string
            memory: string
        livenessProbe:
          exec:
            command: [string]
          httpGet:
            path: string
            port: number
            host: string
            scheme: string
            httpHeaders:
            - name: string
              value: string
          tcpSocket:
            port: number
          initialDelaySeconds: 0
          timeoutSeconds: 0
          periodSeconds: 0
          successThreshold: 0
          failureThreshold: 0
          securityContext:
            privileged: false
        restartPolicy: [Always | Never | OnFailure]
        nodeSelector: object
        imagePullSecrets:
        - name: string
        hostNetwork: false
        volumes:
        - name: string
          emptyDir: {}
          hostPath:
            path: string
          secret:
            secretName: string
            items:
            - key: string
            path: string
          configMap:
            name: string
            items:
            - key: string
              path: string
    

    screenshot

    screenshot

    screenshot

    screenshot

    screenshot

    screenshot

    2. Pod的基本用法

    Pod可用由1个或多个容器组合而成,例如名为frontendPod只由一个容器组成:

    apiVersion: v1
    kind: Pod
    metadata:
      name: frontend
      labels:
        name: frontend
    spec:
      containers:
      - name: frontend
        image: kubeguide/guestbook-php-frontend
        env:
        - name: GET_HOSTS_FROM
          value: env
        ports:
        - containerPort: 80
    

    这个Pod启动后,将启动1个Docker容器另一种场景是,当两个容器为紧耦合关系,应将两个容器打包为一个Pod,如下:

    screenshot

    配置文件frontend-localredis-pod.yaml如下:

    apiVersion: v1
    kind: Pod
    metadata:
      name: redis-php
      labels:
        name: redis-php
    spec:
      containers:
      - name: frontend
        image: kubeguide/guestbook-frontend:localredis
        ports:
        - containerPort: 80
      - name: redis
        image: kubeguide/redis-master
        ports:
        - containerPort: 6379
    

    运行命令创建Pod:

    kubectl create -f frontend-localredis-pod.yaml
    kubectl get pods
    NAME |Ready |status |Restarts |Age
    redis-php |2/2 |Running |0 |10m
    

    可以看到Ready信息为2/2,表示Pod中有两个容器在运行

    查看这个Pod的详细信息,可以看到两个容器的定义及创建过程(Event事件信息)

    #kubectl describe pod redis-php


    链接:https://www.orchome.com/1254
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
     
  • 相关阅读:
    Linux Vim编辑器
    Linux sed 流编辑器
    Shell 编程 (变量和条件测试)
    Linux 下 Bash配置文件读取
    Linux 用户、权限
    Linux 指令(一)文件/目录操作
    Ubuntu 下安装 Swoole
    Mysql IN语句查询
    Mysql 查询优化
    Mysql 获取表属性
  • 原文地址:https://www.cnblogs.com/linux20190409/p/10976300.html
Copyright © 2020-2023  润新知