Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Kubectl & & YAML, in-depth understanding of pod objects (part two)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

View the version of api

[root@k8s-master src] # kubectl api-versions

Admissionregistration.k8s.io/v1

Admissionregistration.k8s.io/v1beta1

Apiextensions.k8s.io/v1

Apiextensions.k8s.io/v1beta1

Apiregistration.k8s.io/v1

Apiregistration.k8s.io/v1beta1

Apps/v1

Authentication.k8s.io/v1

Authentication.k8s.io/v1beta1

Authorization.k8s.io/v1

Authorization.k8s.io/v1beta1

Autoscaling/v1

Autoscaling/v2beta1

Autoscaling/v2beta2

Batch/v1

Batch/v1beta1

Certificates.k8s.io/v1beta1

Coordination.k8s.io/v1

Coordination.k8s.io/v1beta1

Events.k8s.io/v1beta1

Extensions/v1beta1

Networking.k8s.io/v1

Networking.k8s.io/v1beta1

Node.k8s.io/v1beta1

Policy/v1beta1

Rbac.authorization.k8s.io/v1

Rbac.authorization.k8s.io/v1beta1

Scheduling.k8s.io/v1

Scheduling.k8s.io/v1beta1

Storage.k8s.io/v1

Storage.k8s.io/v1beta1

V1

[root@k8s-master src] # kubectl-- help

Kubectl controls the Kubernetes cluster manager.

Find more information at:

Https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):

Create Create a resource from a file or from stdin.

Expose Take a replication controller, service, deployment or pod and

Expose it as a new Kubernetes Service

Run Run a particular image on the cluster

Set Set specific features on objects

Basic Commands (Intermediate):

Explain Documentation of resources

Get Display one or many resources

Edit Edit a resource on the server

Delete Delete resources by filenames, stdin, resources and names, or

By resources and label selector

Deploy Commands:

Rollout Manage the rollout of a resource

Scale Set a new size for a Deployment, ReplicaSet, Replication

Controller, or Job

Autoscale Auto-scale a Deployment, ReplicaSet, or ReplicationController

Cluster Management Commands:

Certificate Modify certificate resources.

Cluster-info Display cluster info

Top Display Resource (CPU/Memory/Storage) usage.

Cordon Mark node as unschedulable

Uncordon Mark node as schedulable

Drain Drain node in preparation for maintenance

Taint Update the taints on one or more nodes

Troubleshooting and Debugging Commands:

Describe Show details of a specific resource or group of resources

Logs Print the logs for a container in a pod

Attach Attach to a running container

Exec Execute a command in a container

Port-forward Forward one or more local ports to a pod

Proxy Run a proxy to the Kubernetes API server

Cp Copy files and directories to and from containers.

Auth Inspect authorization

Advanced Commands:

Diff Diff live version against would-be applied version

Apply Apply a configuration to a resource by filename or stdin

Patch Update field (s) of a resource using strategic merge patch

Replace Replace a resource by filename or stdin

Wait Experimental: Wait for a specific condition on one or many

Resources.

Convert Convert config files between different API versions

Kustomize Build a kustomization target from a directory or a remote url.

Settings Commands:

Label Update the labels on a resource

Annotate Update the annotations on a resource

Completion Output shell completion code for the specified shell (bash or

Zsh)

Other Commands:

Api-resources Print the supported API resources on the server

Api-versions Print the supported API versions on the server, in the form of

"group/version"

Config Modify kubeconfig files

Plugin Provides utilities for interacting with plugins.

Version Print the client and server version information

Usage:

Kubectl [flags] [options]

Use "kubectl-- help" for more information about a given command.

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

Commands).

Generate the yaml file with the run command:

[root@k8s-master src] # kubectl create deployment web-- image=nginx-o yaml-- dry-run > deployment.yaml

[root@k8s-master src] # vim deployment.yaml

ApiVersion: apps/v1

Kind: Deployment

Metadata:

Labels:

App: web

Name: web

Spec:

Replicas: 1

Selector:

MatchLabels:

App: web

Strategy: {}

Template:

Metadata:

Labels:

App: web

Spec:

Containers:

-image: nginx

Name: nginx

Resources: {}

Export a yaml file with the get command

[root@k8s-master src] # kubectl get deploy

NAME READY UP-TO-DATE AVAILABLE AGE

Nginx 1/1 1 1 10h

Web 0/1 1 0 5m41s

Web2 1/1 1 1 7h25m

[root@k8s-master src] # kubectl get deploy web

NAME READY UP-TO-DATE AVAILABLE AGE

Web 0/1 1 0 5m51s

[root@k8s-master src] # kubectl get deploy web-o yaml

ApiVersion: apps/v1

Kind: Deployment

Metadata:

Annotations:

Deployment.kubernetes.io/revision: "1"

CreationTimestamp: "2020-02-12T12:55:39Z"

Generation: 1

Labels:

App: web

Name: web

Namespace: default

ResourceVersion: "56329"

SelfLink: / apis/apps/v1/namespaces/default/deployments/web

Uid: 74f83717-d28b-404e-a8a2-ed6a6bb601b6

Spec:

ProgressDeadlineSeconds: 600

Replicas: 1

RevisionHistoryLimit: 10

Selector:

MatchLabels:

App: web

Strategy:

RollingUpdate:

MaxSurge: 25%

MaxUnavailable: 25%

Type: RollingUpdate

Template:

Metadata:

CreationTimestamp: null

Labels:

App: web

Spec:

Containers:

-image: nginx

ImagePullPolicy: Always

Name: nginx

Resources: {}

TerminationMessagePath: / dev/termination-log

TerminationMessagePolicy: File

DnsPolicy: ClusterFirst

RestartPolicy: Always

SchedulerName: default-scheduler

SecurityContext: {}

TerminationGracePeriodSeconds: 30

Status:

Conditions:

-lastTransitionTime: "2020-02-12T12:55:39Z"

LastUpdateTime: "2020-02-12T12:55:39Z"

Message: Deployment does not have minimum availability.

Reason: MinimumReplicasUnavailable

Status: "False"

Type: Available

-lastTransitionTime: "2020-02-12T12:55:39Z"

LastUpdateTime: "2020-02-12T12:55:39Z"

Message: ReplicaSet "web-d86c95cc9" is progressing.

Reason: ReplicaSetUpdated

Status: "True"

Type: Progressing

ObservedGeneration: 1

Replicas: 1

UnavailableReplicas: 1

UpdatedReplicas: 1

[root@k8s-master src] # kubectl get deploy web-o yaml-- export > deployment2.yaml

Flag-export has been deprecated, This flag is deprecated and will be removed in future.

Comments can be removed.

[root@k8s-master src] # cat deployment2.yaml

ApiVersion: apps/v1

Kind: Deployment

Metadata:

# annotations:

# deployment.kubernetes.io/revision: "1"

# creationTimestamp: null

# generation: 1

Labels:

App: web

Name: web

# selfLink: / apis/apps/v1/namespaces/default/deployments/web

Spec:

# progressDeadlineSeconds: 600

Replicas: 1

# revisionHistoryLimit: 10

Selector:

MatchLabels:

App: web

Strategy:

RollingUpdate:

MaxSurge: 25%

MaxUnavailable: 25%

Type: RollingUpdate

Template:

Metadata:

# creationTimestamp: null

Labels:

App: web

Spec:

Containers:

-image: nginx

ImagePullPolicy: Always

Name: nginx

Resources: {}

# terminationMessagePath: / dev/termination-log

# terminationMessagePolicy: File

# dnsPolicy: ClusterFirst

RestartPolicy: Always

# schedulerName: default-scheduler

# securityContext: {}

# terminationGracePeriodSeconds: 30

# status: {}

After filtering, the following text is obtained:

[root@k8s-master src] # grep-Ev "^ #" deployment2.yaml

ApiVersion: apps/v1

Kind: Deployment

Metadata:

Labels:

App: web

Name: web

Spec:

Replicas: 1

Selector:

MatchLabels:

App: web

Strategy:

RollingUpdate:

MaxSurge: 25%

MaxUnavailable: 25%

Type: RollingUpdate

Template:

Metadata:

Labels:

App: web

Spec:

Containers:

-image: nginx

ImagePullPolicy: Always

Name: nginx

Resources: {}

RestartPolicy: Always

[root@k8s-master src] # kubectl explain pods

KIND: Pod

VERSION: v1

DESCRIPTION:

Pod is a collection of containers that can run on a host. This resource is

Created by clients and scheduled onto hosts.

FIELDS:

ApiVersion

APIVersion defines the versioned schema of this representation of an

Object. Servers should convert recognized schemas to the latest internal

Value, and may reject unrecognized values. More info:

Https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

Kind

Kind is a string value representing the REST resource this object

Represents. Servers may infer this from the endpoint the client submits

Requests to. Cannot be updated. In CamelCase. More info:

Https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

Metadata

Standard object's metadata. More info:

Https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata

Spec

Specification of the desired behavior of the pod. More info:

Https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

Status

Most recently observed status of the pod. This data may not be up to date.

Populated by the system. Read-only. More info:

Https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

[root@k8s-master src] # kubectl explain pods.spec.containers

KIND: Pod

VERSION: v1

RESOURCE: containers

DESCRIPTION:

List of containers belonging to the pod. Containers cannot currently be

Added or removed. There must be at least one container in a Pod. Cannot be

Updated.

A single application container that you want to run within a pod.

FIELDS:

Args

Arguments to the entrypoint. The docker image's CMD is used if this is not

Provided. Variable references $(VAR_NAME) are expanded using the

Container's environment. If a variable cannot be resolved, the reference in

The input string will be unchanged. The $(VAR_NAME) syntax can be escaped

With a double $$, ie: $(VAR_NAME). Escaped references will never be

Expanded, regardless of whether the variable exists or not. Cannot be

Updated. More info:

Https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell

Command

Entrypoint array. Not executed within a shell. The docker image's

ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME)

Are expanded using the container's environment. If a variable cannot be

Resolved, the reference in the input string will be unchanged. The

$(VAR_NAME) syntax can be escaped with a double $$, ie: $(VAR_NAME).

Escaped references will never be expanded, regardless of whether the

Variable exists or not. Cannot be updated. More info:

Https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell

Env

List of environment variables to set in the container. Cannot be updated.

EnvFrom

List of sources to populate environment variables in the container. The

Keys defined within a source must be a C_IDENTIFIER. All invalid keys will

Be reported as an event when the container is starting. When a key exists

In multiple sources, the value associated with the last source will take

Precedence. Values defined by an Env with a duplicate key will take

Precedence. Cannot be updated.

Image

Docker image name. More info:

Https://kubernetes.io/docs/concepts/containers/images This field is

Optional to allow higher level config management to default or override

Container images in workload controllers like Deployments and StatefulSets.

ImagePullPolicy

Image pull policy. One of Always, Never, IfNotPresent. Defaults to Always

If: latest tag is specified, or IfNotPresent otherwise. Cannot be updated.

More info:

Https://kubernetes.io/docs/concepts/containers/images#updating-images

Lifecycle

Actions that the management system should take in response to container

Lifecycle events. Cannot be updated.

LivenessProbe

Periodic probe of container liveness. Container will be restarted if the

Probe fails. Cannot be updated. More info:

Https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

Name-required-

Name of the container specified as a DNS_LABEL. Each container in a pod

Must have a unique name (DNS_LABEL). Cannot be updated.

Ports

List of ports to expose from the container. Exposing a port here gives the

System additional information about the network connections a container

Uses, but is primarily informational. Not specifying a port here DOES NOT

Prevent that port from being exposed. Any port which is listening on the

Default "0.0.0.0" address inside a container will be accessible from the

Network. Cannot be updated.

ReadinessProbe

Periodic probe of container service readiness. Container will be removed

From service endpoints if the probe fails. Cannot be updated. More info:

Https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

Resources

Compute Resources required by this container. Cannot be updated. More info:

Https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/

SecurityContext

Security options the pod should run with. More info:

Https://kubernetes.io/docs/concepts/policy/security-context/ More info:

Https://kubernetes.io/docs/tasks/configure-pod-container/security-context/

StartupProbe

StartupProbe indicates that the Pod has successfully initialized. If

Specified, no other probes are executed until this completes successfully.

If this probe fails, the Pod will be restarted, just as if the

LivenessProbe failed. This can be used to provide different probe

Parameters at the beginning of a Pod's lifecycle, when it might take a long

Time to load data or warm a cache, than during steady-state operation. This

Cannot be updated. This is an alpha feature enabled by the StartupProbe

Feature flag. More info:

Https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

Stdin

Whether this container should allocate a buffer for stdin in the container

Runtime. If this is not set, reads from stdin in the container will always

Result in EOF. Default is false.

StdinOnce

Whether the container runtime should close the stdin channel after it has

Been opened by a single attach. When stdin is true the stdin stream will

Remain open across multiple attach sessions. If stdinOnce is set to true

Stdin is opened on container start, is empty until the first client

Attaches to stdin, and then remains open and accepts data until the client

Disconnects, at which time stdin is closed and remains closed until the

Container is restarted. If this flag is false, a container processes that

Reads from stdin will never receive an EOF. Default is false

TerminationMessagePath

Optional: Path at which the file to which the container's termination

Message will be written is mounted into the container's filesystem. Message

Written is intended to be brief final status, such as an assertion failure

Message. Will be truncated by the node if greater than 4096 bytes. The

Total message length across all containers will be limited to 12kb.

Defaults to / dev/termination-log. Cannot be updated.

TerminationMessagePolicy

Indicate how the termination message should be populated. File will use the

Contents of terminationMessagePath to populate the container status message

On both success and failure. FallbackToLogsOnError will use the last chunk

Of container log output if the termination message file is empty and the

Container exited with an error. The log output is limited to 2048 bytes or

80 lines, whichever is smaller. Defaults to File. Cannot be updated.

Tty

Whether this container should allocate a TTY for itself, also requires

'stdin' to be true. Default is false.

VolumeDevices

VolumeDevices is the list of block devices to be used by the container.

This is a beta feature.

VolumeMounts

Pod volumes to mount into the container's filesystem. Cannot be updated.

WorkingDir

Container's working directory. If not specified, the container runtime's

Default will be used, which might be configured in the container image.

Cannot be updated.

1:15:00

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report