"In-depth analysis Kubernetes - 12 small chopper pilot: My first container applications."
Includes two steps: the preparation and production of image yaml profile (or json)
Nginx as an example to the deployment
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80
Wherein the kind field declared type, e.g. deployment, daemonset the like, Metadata is specifically described, for example, name, namespace, labels, annotations, etc.
spec.template describes the details of the pod, i.e., container configuration template
Creating deployment
$ kubectl create -f nginx-deployment.yaml
View deployment operation
$ kubectl get pods -l app=nginx NAME READY STATUS RESTARTS AGE n ginx-deployment-67594d6bf6-9gdvr 1/1 Running 0 10m nginx-deployment-67594d6bf6-v6j7w 1/1 Running 0 10m
View details of API objects
kubectl describe pod nginx-deployment-67594d6bf6-9gdvr Name: nginx-deployment-67594d6bf6-9gdvr Namespace: default Priority: 0 PriorityClassName: <none> Node: node-1/10.168.0.3 Start Time: Thu, 16 Aug 2018 08:48:42 +0000 Labels: app=nginx pod-template-hash=2315082692 Annotations: <none> Status: Running IP: 10.32.0.23 Controlled By: ReplicaSet/nginx-deployment-67594d6bf6 ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 1m default-scheduler Successfully assigned default/nginx-deployment-67594d6bf6-9gdvr to node-1 Normal Pulling 25s kubelet, node-1 pulling image "nginx:1.7.9" Normal Pulled 17s kubelet, node-1 Successfully pulled image "nginx:1.7.9" Normal Created 17s kubelet, node-1 Created container Normal Started 17s kubelet, node-1 Started container
Events which have late field can be used to locate the problem, common
(1) find a suitable node node schedules pod, comprising
match node is not the node label;
node node resources are not enough;
node node has the stain;
abnormal nodes in the network node;
(2) pull the mirror fails
Container mirrored version upgrade
... spec: Containers: - name: nginx Image: nginx: # 1.8 here is modified from 1.7.9 to 1.8 the ports: - containerPort: 80
carried out
$ kubectl replace -f nginx-deployment.yaml
The more common way is to apply through the implementation of related operations, whether it is created or modified can be done through the command
$ Kubectl apply -f nginx-deployment.yaml # nginx-deployment.yaml modify the content of $ kubectl apply -f nginx-deployment.yaml
The following is an example of a mounted volume
EmptyDir and is usually divided into two kinds hostPath, the difference is that the former does not need to specify the host directory (source directory), K8S creates a temporary directory on the host and mount it; and the latter is linked to the need to explicitly declare contained in the source directory, for example, host computer / usr / local / nginx / html directory is mounted to the same position of the container
emptyDir examples
volumes: - name: nginx-vol emptyDir: {} hostPath的例子 ... volumes: - name: nginx-vol hostPath: path: /var/data
Into the container
$ kubectl exec -it nginx-deployment-5c678cfb6d-lg9lw -- /bin/bash # ls /usr/share/nginx/html
Delete container
$ Kubectl delete -F nginx deployment.yaml