In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
"in-depth analysis of the Kubernetes-12 pilot: my first containerized application"
It mainly includes two steps: making an image and writing a yaml configuration file (or json)
Take deployment of nginx as an example
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
The kind field declares types, such as deployment, daemonset, etc., and metadata is a specific description, such as name, namespace, labels, annotations, etc.
Spec.template describes the details of pod, that is, the template for container configuration
Create deployment
$kubectl create-f nginx-deployment.yaml
View the operation of deployment
$kubectl get pods-l app=nginx NAME READY STATUS RESTARTS AGE nginx-deployment-67594d6bf6- 9gdvr 1 app=nginx NAME READY STATUS RESTARTS AGE nginx-deployment-67594d6bf6- 9gdvr 1 Running 0 10m nginx-deployment-67594d6bf6-v6j7w 1 Running 0 10m
View API object details
Kubectl describe pod nginx-deployment-67594d6bf6-9gdvrName: nginx-deployment-67594d6bf6-9gdvrNamespace: defaultPriority: 0PriorityClassName: Node: node-1/10.168.0.3Start Time: Thu 16 Aug 2018 08:48:42 + 0000Labels: app=nginx pod-template-hash=2315082692Annotations: Status: RunningIP: 10.32.0.23Controlled 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
The Events field can be used to locate later problems, and the common ones are
(1) unable to find a suitable node node scheduling pod, including
Node node label mismatch
Insufficient allocation of node node resources
The node node is blemished
Node node network exception
(2) failed to pull image
Upgrade container image version
... Spec: containers:-name: nginx image: nginx:1.8 # here has been modified from 1.7.9 to 1.8 ports:-containerPort: 80
Execution
$kubectl replace-f nginx-deployment.yaml
A more common way is to perform relevant operations through apply, which can be created or modified through this command
$kubectl apply-f nginx-deployment.yaml # modify the contents of nginx-deployment.yaml $kubectl apply-f nginx-deployment.yaml
Here is an example of a volume mount
It is usually divided into emptyDir and hostPath. The difference between the two is that the former does not need to specify a host directory (source directory), while K8s creates a temporary directory on the host and mounts it, while the latter needs to explicitly declare the mounted source directory, such as mounting the host's / usr/local/nginx/html directory to the same location of the container
The example of emptyDir
An example of volumes:-name: nginx-vol emptyDir: {} hostPath. Volumes:-name: nginx-vol hostPath: path: / var/data
Enter the container
$kubectl exec-it nginx-deployment-5c678cfb6d-lg9lw-/ bin/bash # ls / usr/share/nginx/html
Delete Container
$kubectl delete-f nginx-deployment.yaml
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.