Source of the container
Use nginx’s official container image.
There are two ways to publish containers
Now that we have the image, how do we commit it to K8S for execution? There are two ways:
- Cli mode (not recommended).
- Configuration file mode (recommended).
The official recommended second method is used here, which is to commit the various container information to K8S by writing it to a configuration file.
Define the container configuration file
Create an nginx.yaml file
[root@master01 ~]# cat nginx.yaml apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: Nginx :1.7.9 ports: -containerPort: 80 hostAliases: -ip: "10.20.20.20" Hostnames: "test1.com" - "test2.com"Copy the code
Deploy containers to K8S
[root@master01 ~]# kubectl apply -f nginx.yaml
pod/nginx created
Copy the code
View the container in action
[root@master01 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 93s 192.10.205.195 work01 <none> <none>
Copy the code
View specific information about a container
All important actions are recorded in the Events returned by the Kubectl Describe directive for DEBUG
[root@master01 ~]# kubectl describe pod Name: nginx Namespace: default Priority: 0 Node: work03/192.168.10.17 IP: 192.10.137.130... Omit... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled <unknown> default-scheduler Successfully assigned default/nginx to work03 Normal Pulled 74s kubelet, Work03 Container image "nginx:1.7.9" already present on machine Normal Created 73s kubelet, work03 Created container nginx Normal Started 73s kubelet, work03 Started container nginxCopy the code
Upgrade the nginx version in the container
Yaml image: nginx:1.9.0 # kubectl apply-f nginx.yamlCopy the code
Delete the container application
[root@master01 ~]# kubectl delete -f nginx.yaml
pod "nginx" deleted
[root@master01 ~]# kubectl get pods
No resources found in default namespace.
Copy the code
Introduction to nginx.yaml parameters
Metadata stores metadata. The Spec stores a specific definition of the object that describes the kind of function it expresses: A Pod object is an API object of type Pod that operates on the identity of another API object, Pod Metadata. The Pod identifier spec.containers indicates that it is a container and the related parameter spec.hostAliases adds resolution to the /etc/hosts file of the containerCopy the code
See the Pod help documentation
[root@master01 ~]# kubectl explain Pod
Copy the code
conclusion
A container application for K8S was released today.
As we can see, containers ensure consistency of “system environment” in development/test/production, and YAML configuration files ensure consistency of “configuration parameters”.
But it’s a little confusing, isn’t it a publishing container, and what is Pod?
Pod wraps the container. The smallest unit K8S can operate on is Pod, which contains the container