kubectl && YAML,深入理解pod对象(上)

image.png

image.png

image.png

[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 <command> --help" for more information about a given command.

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

commands).

[root@k8s-master src]# kubectl create deployment web2 --image=nginx

deployment.apps/web2 created

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

NAME                     READY   STATUS    RESTARTS   AGE

nginx-86c57db685-wpkxv   1/1     Running   0          3h24m

web2-6884cc5665-qr9bh    1/1     Running   0          7s


[root@k8s-master src]# kubectl create deployment web2 --image=nginx

deployment.apps/web2 created

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

NAME                     READY   STATUS    RESTARTS   AGE

nginx-86c57db685-wpkxv   1/1     Running   0          3h24m

web2-6884cc5665-qr9bh    1/1     Running   0          7s

[root@k8s-master src]# docker pull nginx

Using default tag: latest

latest: Pulling from library/nginx

bc51dd8edc1b: Pulling fs layer 

66ba67045f57: Pulling fs layer 

bf317aa10aa5: Pulling fs layer 

latest: Pulling from library/nginx

bc51dd8edc1b: Pull complete 

66ba67045f57: Pull complete 

bf317aa10aa5: Pull complete 

Digest: sha256:ad5552c786f128e389a0263104ae39f3d3c7895579d45ae716f528185b36bc6f

Status: Downloaded newer image for nginx:latest

docker.io/library/nginx:latest

[root@k8s-master src]# kubectl create service nodeport web-service --tcp=80:80

service/web-service created

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

NAME          TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE

kubernetes    ClusterIP   10.1.0.1      <none>        443/TCP        8h

nginx         NodePort    10.1.131.49   <none>        80:32232/TCP   8h

web-service   NodePort    10.1.79.198   <none>        80:31485/TCP   20s

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

NAME          ENDPOINTS            AGE

kubernetes    192.168.1.111:6443   8h

nginx         10.244.2.2:80        8h

web-service   <none>               28s

[root@k8s-master src]# kubectl expose deployment web2 --port=80 --target-port=80 --type=NodePort

service/web2 exposed

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

NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE

kubernetes    ClusterIP   10.1.0.1       <none>        443/TCP        8h

nginx         NodePort    10.1.131.49    <none>        80:32232/TCP   8h

web-service   NodePort    10.1.79.198    <none>        80:31485/TCP   2m40s

web2          NodePort    10.1.238.100   <none>        80:30634/TCP   13s

image.png



猜你喜欢

转载自blog.51cto.com/chenjisong/2470532