Kubernetes Basics

Copyright: original works, posted please indicate the source! https://blog.csdn.net/sa19861211/article/details/90487995

1. kubeadm command

1.1 the master node cluster initialization Kubernetes

kubeadm init <args>

1.2 add nodes to the cluster

kubeadm join

1.3 lists, create and delete token

kubeadm token

2. kubectl command

View kubectl version

kubectl version
  • Node

To get the name of the cluster nodes

kubectl get nodes
  • Under

1, View pod Information

kubectl get pod

2, view the status of a particular pod

kubectl get -f myapp.yaml

3, see the pod of yaml

kubectl get pods frontend-9si5l -o yaml

4. Delete service

kubectl delete services hello-minikube

5, delete deployment

kubectl delete deployment hello-minikube
  • Namespace

1, check the specified context information of pod

kubectl get pods --context=minikube

2, lists the cluster current namespace

kubectl get namespace

3, query context configuration

kubectl config view | grep namespace

4, to see what Kubernetes resources (not) namespace

kubectl api-resources --namespaced=true|false
  • Selector

1, according to the field selector filter pod

kubectl get pods --field-selector ""

2, choose not default all Kubernetes service namespace

kubectl get services --field-selector metadata.namespace!=default
  • Init Container

1, see the init container log

kubectl logs myapp-pod -c init-mydb
  • Cron Job

1. List all Job

kubectl get jobs

2, see the Cron Job status information

kubectl get cronjob hello

3, wait and observe the creation of the Job

kubectl get jobs --watch

4, delete Cron Job

kubectl delete cronjob hello

5, delete all namespaces in the current Job

kubectl delete jobs --all

6, delete the Job

kubectl delete jobs/pi

or

  kubectl delete -f ./job.yaml
  • ReplicaSet

1, will be submitted to Kubernetes frontend.yaml cluster will create Pod replica set and its management has been defined

kubectl apply -f https://kubernetes.io/examples/controllers/frontend.yaml

2, view the deployed replica set information

kubectl get rs

3, check the status of the replica set

kubectl get rs
  • ReplicationController

1, the status check ReplicationController

kubectl describe replicationcontrollers/nginx
  • Deployment

1, automatic expansion

kubectl scale deployment nginx-deployment --replicas=10
  • Service

1, see Service Information

kubectl get svc my-nginx

2, see the description of Service

kubectl describe svc my-nginx

3, View Endpoinit information

kubectl get ep my-nginx
  • Ingress

1, see the description of Ingress

kubectl describe ingress simple-fanout-example

2, edit Ingress

kubectl edit ingress test

or

kubectl replace -f 修改后的Ingress yaml文件
  • Label

1, the label is attached to node

kubectl label nodes <node-name> <label-key>=<label-value>

2, the node checks whether there are now tag to verify whether it is valid

kubectl get nodes --show-labels

3, a given node to view a complete list of tags
kubectl describe node "nodename"

  • Taints and Tolerations

1, taint a node

kubectl taint nodes node1 key1=value1:NoSchedule
kubectl taint nodes node1 key1=value1:NoExecute
kubectl taint nodes node1 key2=value2:NoSchedule
  • Secret

1, kubectl create Secret

#Create files needed for rest of example.
echo -n "admin" > ./username.txt
echo -n "1f2d1e2e67df" > ./password.txt
kubectl create secret generic db-user-pass --from-file=./username.txt --from-file=./password.txt

2, View Secret

kubectl get secrets
kubectl get secret mysecret -o yaml

3, manually create Secret

$ echo -n "admin" | base64
YWRtaW4=
$ echo -n "1f2d1e2e67df" | base64
MWYyZDFlMmU2N2Rm

Secret configuration objects in secret.yaml file:

apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  username: YWRtaW4=
  password: MWYyZDFlMmU2N2Rm

Use kubectl create command to create a Secret

kubectl create -f ./secret.yaml

Decoding the password field:

echo "MWYyZDFlMmU2N2Rm" | base64 --decode

Guess you like

Origin blog.csdn.net/sa19861211/article/details/90487995