Kubernetes resource list definition
Kubernetes is a ReSTful API
GET,PUT,DELETE,POST
kubectl run ,get,edit
Resources, objects
workload: Pod, replicate, Statefulset, Daemonset, job, Cronjob, etc
Service discovery and load balancing: service, Ingress
Configuration and storage: Volume, CSI
ConfigMap,Secret
DownwardAPI
Cluster level resources
Namespace, Node, Role, ClusterRole, rolebinding (Role binding), clusterrolebinding (cluster Role binding)
Metadata resources
HPA, podtemplate, limitrange
Three levels of api Group: apiversion
Beta version
beta test version public test (unstable)
v1 stable version
In general, you can use the configuration list to create
Let's take a look at the Pod we created earlier
[root@master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE client 1/1 Running 0 11h myapp-848b5b879b-4xpl7 1/1 Running 0 10h myapp-848b5b879b-7gtn4 1/1 Running 0 10h myapp-848b5b879b-xtcdd 1/1 Running 0 10h nginx-deploy-5b595999-fsxlp 1/1 Running 0 11h
[root@master ~]# kubectl get pod myapp-848b5b879b-4xpl7 NAME READY STATUS RESTARTS AGE myapp-848b5b879b-4xpl7 1/1 Running 0 10h [root@master ~]# kubectl get pod myapp-848b5b879b-4xpl7 -o yaml apiVersion: v1 kind: Pod #category metadata: #Nested field creationTimestamp: 2018-09-04T17:07:58Z generateName: myapp-848b5b879b- labels: pod-template-hash: "4046164356" run: myapp name: myapp-848b5b879b-4xpl7 namespace: default ownerReferences: - apiVersion: apps/v1 blockOwnerDeletion: true controller: true kind: ReplicaSet name: myapp-848b5b879b uid: 41924f50-b061-11e8-a432-000c29f33006 resourceVersion: "10899" selfLink: /api/v1/namespaces/default/pods/myapp-848b5b879b-4xpl7 uid: 1259f6af-b065-11e8-a432-000c29f33006 spec: #Very important fields, resource specifications containers: - image: ikubernetes/myapp:v1 imagePullPolicy: IfNotPresent name: myapp resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount name: default-token-8zzcr readOnly: true dnsPolicy: ClusterFirst nodeName: node1 priority: 0 restartPolicy: Always schedulerName: default-scheduler securityContext: {} serviceAccount: default serviceAccountName: default terminationGracePeriodSeconds: 30 tolerations: - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 300 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 300 volumes: - name: default-token-8zzcr secret: defaultMode: 420 secretName: default-token-8zzcr status:#Read only fields conditions: - lastProbeTime: null lastTransitionTime: 2018-09-04T17:07:57Z status: "True" type: Initialized - lastProbeTime: null lastTransitionTime: 2018-09-04T17:07:58Z status: "True" type: Ready - lastProbeTime: null lastTransitionTime: null status: "True" type: ContainersReady - lastProbeTime: null lastTransitionTime: 2018-09-04T17:07:58Z status: "True" type: PodScheduled containerStatuses: - containerID: docker://8e757445c75729e865de6462d7dc4e849909776f8a34657ceab3f11baf569c0d image: ikubernetes/myapp:v1 imageID: docker-pullable://ikubernetes/myapp@sha256:9c3dc30b5219788b2b8a4b065f548b922a34479577befb54b03330999d30d513 lastState: {} name: myapp ready: true restartCount: 0 state: running: startedAt: 2018-09-04T17:07:58Z hostIP: 192.168.68.20 phase: Running podIP: 10.244.1.8 qosClass: BestEffort startTime: 2018-09-04T17:07:57Z
How to create a resource:
Apserver only receives resource definitions in JSON format;
The configuration list provided in yaml format can be automatically converted into json format by apiserver, and then submitted
Format list of most resources:
apiVersion which group and version to create belongs to, pay attention to the case of kubectl API versions
kind: resource category
Metadata: metadata
name
namespace
labels
annotations
PATH of each resource reference
/api/GROUP/VERSION/namespaces/NAMESPACE/TYPE/NAME
Replacement of uppercase
spec: desired state
status: current state. This field is created by kubernets to make the current state close to the desired state
See how the pod resource defines kubectl explain pods
Create the first yaml file: two containers created on top of a pod
[root@master manifests]# cat pod-demo.yaml apiVersion: v1 kind: Pod metadata: name: pod-demo namespace: default labels: app: myapp tier: frontend spec: containers: - name: myapp image: ikubernetes/myapp:v1 - name: busybox image: busybox:latest command: - "/bin/sh" - "-c" - "sleep 3600"
Start creation: kubectl create -f pod-demo.yaml
View your own creation: kubectl get pod
[root@master manifests]# kubectl get pod NAME READY STATUS RESTARTS AGE client 1/1 Running 0 13h myapp-848b5b879b-4xpl7 1/1 Running 0 12h myapp-848b5b879b-7gtn4 1/1 Running 0 12h myapp-848b5b879b-xtcdd 1/1 Running 0 12h nginx-deploy-5b595999-fsxlp 1/1 Running 0 13h pod-demo 2/2 Running 0 1m
Delete your own creation: kubectl delete - f pod demo.yaml
Get the details of the pod demo you just created:
kubectl describe pods pod-demo
[root@master manifests]# kubectl describe pods pod-demo Name: pod-demo #Resource name Namespace: default #Namespace Priority: 0 PriorityClassName: <none> Node: node2/192.168.68.30 #Which node is running on Start Time: Wed, 05 Sep 2018 13:33:26 +0800 Labels: app=myapp #Label tier=frontend Annotations: <none> Status: Running IP: 10.244.2.10 Containers: myapp: #First container Container ID: docker://aa6be83a949e31c1935fe607e9238fd3bc64b51bfa851350ea502c31371d07e4 Image: ikubernetes/myapp:v1 Image ID: docker-pullable://ikubernetes/myapp@sha256:9c3dc30b5219788b2b8a4b065f548b922a34479577befb54b03330999d30d513 Port: <none> Host Port: <none> State: Running Started: Wed, 05 Sep 2018 13:33:26 +0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-8zzcr (ro) busybox: #Second container Container ID: docker://942c9ee53afcc890cbd1471877c5ecca238a8eb9de40fd5399bc3bbfd9e42d28 Image: busybox:latest Image ID: docker-pullable://busybox@sha256:cb63aa0641a885f54de20f61d152187419e8f6b159ed11a251a09d115fdff9bd Port: <none> Host Port: <none> Command: /bin/sh -c sleep 3600 State: Running Started: Wed, 05 Sep 2018 13:33:31 +0800 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-8zzcr (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: default-token-8zzcr: Type: Secret (a volume populated by a Secret) SecretName: default-token-8zzcr Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: #Created details Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 3m default-scheduler Successfully assigned default/pod-demo to node2 Normal Pulled 3m kubelet, node2 Container image "ikubernetes/myapp:v1" already present on machine Normal Created 3m kubelet, node2 Created container Normal Started 3m kubelet, node2 Started container Normal Pulling 3m kubelet, node2 pulling image "busybox:latest" Normal Pulled 3m kubelet, node2 Successfully pulled image "busybox:latest" Normal Created 3m kubelet, node2 Created container Normal Started 3m kubelet, node2 Started container
See myapp Access log for: [root@master manifests]# curl 10.244.2.10 #ip is generated above Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a> [root@master manifests]# kubectl logs pod-demo myapp 10.244.0.0 - - [05/Sep/2018:05:45:35 +0000] "GET / HTTP/1.1" 200 65 "-" "curl/7.29.0" "-" 10.244.0.0 - - [05/Sep/2018:05:45:44 +0000] "GET / HTTP/1.1" 200 65 "-" "curl/7.29.0" "-" pod Monitoring created: kubectl get pods -w //To delete a pod demo project: [root@master manifests]# kubectl delete pods pod-demo pod "pod-demo" deleted [root@master manifests]# kubectl get pod NAME READY STATUS RESTARTS AGE client 1/1 Running 0 13h myapp-848b5b879b-4xpl7 1/1 Running 0 12h myapp-848b5b879b-7gtn4 1/1 Running 0 12h myapp-848b5b879b-xtcdd 1/1 Running 0 12h nginx-deploy-5b595999-fsxlp 1/1 Running 0 13h
adopt kubectl api-versions You can check it. api Version [root@master ~]# kubectl api-versions admissionregistration.k8s.io/v1beta1 apiextensions.k8s.io/v1beta1 apiregistration.k8s.io/v1 apiregistration.k8s.io/v1beta1 apps/v1 apps/v1beta1 apps/v1beta2 authentication.k8s.io/v1 authentication.k8s.io/v1beta1 #Beta version authorization.k8s.io/v1 authorization.k8s.io/v1beta1 autoscaling/v1 autoscaling/v2beta1 batch/v1 batch/v1beta1 certificates.k8s.io/v1beta1 events.k8s.io/v1beta1 extensions/v1beta1 networking.k8s.io/v1 policy/v1beta1 rbac.authorization.k8s.io/v1 rbac.authorization.k8s.io/v1beta1 scheduling.k8s.io/v1beta1 storage.k8s.io/v1 storage.k8s.io/v1beta1 v1