Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Ⅰ:Command Outline

1、Basic command

1>create Build resource by filename or standard input

2>expose Expose a resource as a new Service

3>run Run a specified image in a cluster

4>set Set a specified function for an object

5>get Get one or multiple resource

6>explain Document reference

7>edit Edit a resource using the default editor

8>delete Deletes a resource by filename, standard input, resource name, or label selector


2、Deployment command

1>rollout Rollout of management resource

2>rolling-update Rolling updates to a given replication controller

3>scale Expand or shrink the scale of Pod,Deployment、ReplicaSet、RC or Job

4>autoscale Create an automatic option to expand or shrink and set the number of pods


3、Cluster management command

1>certificate Modify certificate resource

2>cluster-info display cluster information

3>top display resource(CPU/Memory/Storage) usage。Need Heapster execution

4>cordon The token node is not dispatchable

5>uncordon The token node is dispatchable

6>drain Exclude nodes during maintenance

...

7>Marked as a taint, no dispatchable task


4、Troubleshooting and debugging commands

1>describe Display detailed information about a particular resource or group of resources

2>logs Print a docker log in a Pod.If the Pod has only one docker, the docker's name is optional

3>attach Attach to a running docker

4>exec Execute the command to a docker

5>port-forward Forward one or more local ports to a pod

6>proxy Run a proxy to the Kubernetes API server

7>cp Copy files or directories into docker

8>auth Check authorization


5、Senior command

1>apply Applies a configuration to a resource by filename or standard input

2>patch Use patches to modify and update the fields of the resource

3>replace Replaces a resource with a filename or standard input

4>convert Convert configuration files between different API versions


6、Setting command

1>label Update the resource lable

2>annotate Update the resource annotate

3>completion Used to implement automatic completion of kubectl tool


7、Other commands

1>api-versions Print the supported API version

2>config Modify the kubeconfig file (for accessing apis, such as configuring authentication information)

3>help All commands

4>plugin Run a command-line plug-in

5>version Print client and service version information


Ⅱ:kubectl tool management cluster

...

kubectl -n onap cp copy_test.sh dev-vfc-catalog-68cb7c9878-v4kt2: -c vfc-catalog
Copy pod's content to local:
kubectl -n onap cp dev-vfc-catalog-68cb7c9878-v4kt2:copy_test.sh -c vfc-catalog /tmp/copy_test.sh

6、Remote command (to see the current path of the container as an example)
kubectl -n onap exec -it dev-vfc-catalog-68cb7c9878-v4kt2 -c vfc-catalog pwd

7、View pod basic information and logs (no -c parameter added for single container pod)
kubectl -n onap describe pod dev-vfc-catalog-68cb7c9878-v4kt2
kubectl -n onap logs dev-vfc-catalog-68cb7c9878-v4kt2 -c vfc-catalog

8、Check the service listener port and manually expose the port, which is commonly used for testing, such as nginx under test namespace

1>Build namespace
kubectl create namespace test
2>create pod with 3 replication
kubectl run nginx --image=nginx --replicas=3 -n test
3>Pod exposed ports for nginx (target port, source port target-port)
kubectl expose deployment nginx --port=88 --target-port=80 --type=LoadBalancer -n test
or
kubectl expose deployment nginx --port=88 --target-port=80 --type=NodePort -n test

4> Check svc(ports that pod exposed , The cluster internally accesses this pod via port 88., external access to the cluster using floatingip+30531)
kubectl get svc -n test
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx LoadBalancer 10.43.45.186 10.0.0.3 88:30531/TCP 3m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx NodePort 10.43.45.186 88:30531/TCP 3m
Nodes within the CLUSTER can be accessed via cluster-ip +88 port
Outside the cluster, it is accessible via either EXTERNAL IP or the Floating IP+30531, which is the node name of the pod
The floatingip corresponding to the node name can be viewed in the /etc/hosts of the rancher machine or in the documentation


9、 Modify the container image and pod strategy (deployment, statefulset), the completion of modification will trigger the rolling update

1>To determine whether the pod is a stateful application (efullset) or a stateful application (deployment)
kubectl -n onap describe pod dev-vfc-catalog-68cb7c9878-v4kt2 |grep Controlled
2>Stateless application

...

deployment 
kubectl -n onap get deploy |grep

...

catalog 
kubectl -n onap edit deploy dev-vfc-catalog-68cb7c9878-v4kt2
3>Stateful application statefulset
kubectl -n onap get statefulset |grep cassandra
kubectl -n onap edit statefulset dev-aai-

...

cassandra 


10、Restart pod(After removing the pod, deployment will recreate a same pod and randomly assign it to any node.)
kubectl -n onap delete pod dev-vfc-catalog-68cb7c9878-v4kt2 -c vfc-catalog

...