当前位置:网站首页>Kubernetes simple introduction to writing YML
Kubernetes simple introduction to writing YML
2022-07-03 00:28:00 【dream21st】
To write kubernetes Of yml Resource list has 5 Top level fields :apiVersion、kind、metadata、spec、status.
# If there is no given group name , Then the default is core, have access to kubectl apiversions # Get current k8s All on the version apiVersion Version information ( Each version may not Same as )
apiVersion: group/apiversion
# Resource categories
kind:
# Resource metadata
metadata:
name
namespace
lables
annotations # The main purpose is to facilitate users to read and find
# Desired state (disired state)
spec:
# current state , This field has Kubernetes Self maintenance , Users cannot define
status:
Use kubectl Commands can be viewed apiVersion Version information of :
[[email protected] ~]# kubectl api-versions
Get the field setting help document
[[email protected] ~]# kubectl explain pod
The resource list can be roughly divided into the following types :
apiVersion <string> # Represents string type
metadata <Object> # Indicates that you need to nest multiple fields
labels <map[string]string> # By k:v The mapping of components
finalizers <[]string> # Represents a list of strings
ownerReferences <[]Object> # Represents a list of objects
hostPID <boolean> # Boolean type
priority <integer> # integer
name <string> -required- # If the type is followed by -required-, Indicates a required field
1 establish nameSpace
Write a yml file , The name of the document is dream21thnamespaces.yml, The contents of the document are as follows :
apiVersion: v1
kind: Namespace
metadata:
name: dream21th
Upload to server , Execute the following instructions , You can see that the created name is dream21th Of namespace:
[[email protected] namespaces]# kubectl apply -f dream21thnamespaces.yml
namespace/dream21th created
[[email protected] namespaces]# kubectl get ns
NAME STATUS AGE
default Active 119d
dream21th Active 7s
kube-node-lease Active 119d
kube-public Active 119d
kube-system Active 119d
Execute the following instructions to delete dream21th Of namespace:
[[email protected] namespaces]# kubectl delete -f dream21thnamespaces.yml
namespace "dream21th" deleted
2 establish pod
Write a yml file , The name of the document is dream21thtomcatpod.yml, The contents of the document are as follows :
apiVersion: v1
kind: Pod
metadata:
name: dream21th-tomcat-pod
labels:
app: dream21th-tomcat-pod
spec:
containers:
- name: dream21th-tomcat-pod
image: tomcat:9.0.20-jre8-alpine
imagePullPolicy: IfNotPresent
restartPolicy: Always
Upload to server , Execute the following instructions :
[[email protected] pod]# kubectl apply -f dream21thtomcatpod.yml
pod/dream21th-tomcat-pod created
[[email protected] pod]# kubectl get pod
NAME READY STATUS RESTARTS AGE
dream21th-tomcat-pod 1/1 Running 0 7s
[[email protected] pod]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
dream21th-tomcat-pod 1/1 Running 0 14s 10.244.1.8 k8s-work1 <none> <none>
[[email protected] pod]# curl 10.244.1.8:8080
Image Download Strategy 、 Restart strategy :
imagePullPolicy:
Always: Always pull pull
IfNotPresent: If there is a mirror image locally , Use local , If there is no image locally , Download mirroring .
Never: Use only local images , Never pull
restartPolicy:
Always: Just exit and restart .
OnFailure: When you fail to exit (exit code Not for 0) To restart
Never: Never restart
Delete the deployed above pod:
[[email protected] pod]# kubectl delete -f dream21thtomcatpod.yml
pod "dream21th-tomcat-pod" deleted
[[email protected] pod]# kubectl get pod
No resources found in default namespace.
3 establish deployment
Write a yml file , The name of the document is dream21thtomcatdeployment.yml, The contents of the document are as follows :
apiVersion: apps/v1
kind: Deployment
metadata:
name: dream21th-tomcat-deployment
labels:
app: dream21th-tomcat-deployment
spec:
replicas: 3
template:
metadata:
name: dream21th-tomcat-deployment
labels:
app: dream21th-tomcat
spec:
containers:
- name: dream21th-tomcat-deployment
image: tomcat:9.0.20-jre8-alpine
imagePullPolicy: IfNotPresent
restartPolicy: Always
selector:
matchLabels:
app: dream21th-tomcat
Upload to server , Execute the following instructions :
[[email protected] deployment]# kubectl apply -f dream21thtomcatdeployment.yml
deployment.apps/dream21th-tomcat-deployment created
[[email protected] deployment]# kubectl get pods
NAME READY STATUS RESTARTS AGE
dream21th-tomcat-deployment-5fc846c9bc-5rvkq 1/1 Running 0 10s
dream21th-tomcat-deployment-5fc846c9bc-j95mc 1/1 Running 0 10s
dream21th-tomcat-deployment-5fc846c9bc-ks88d 1/1 Running 0 10s
[[email protected] deployment]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
dream21th-tomcat-deployment-5fc846c9bc-5rvkq 1/1 Running 0 18s 10.244.2.5 k8s-work2 <none> <none>
dream21th-tomcat-deployment-5fc846c9bc-j95mc 1/1 Running 0 18s 10.244.1.10 k8s-work1 <none> <none>
dream21th-tomcat-deployment-5fc846c9bc-ks88d 1/1 Running 0 18s 10.244.1.9 k8s-work1 <none> <none>
[[email protected] deployment]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
dream21th-tomcat-deployment 3/3 3 3 28s
[[email protected] deployment]# kubectl get deployment -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
dream21th-tomcat-deployment 3/3 3 3 33s dream21th-tomcat-deployment tomcat:9.0.20-jre8-alpine app=dream21th-tomcat
Be careful : stay Deployment You have to write matchLables;selector.matchLabels.app The value of and template.metadata.labels.app Agreement .
It can be verified by the following instructions :
[[email protected] deployment]# curl 10.244.2.5:8080
You can delete the deployed above through the following instructions deployment:
[[email protected] deployment]# kubectl delete -f dream21thtomcatdeployment.yml
deployment.apps "dream21th-tomcat-deployment" deleted
[[email protected] deployment]# kubectl get pods
No resources found in default namespace.
4 establish service
Write a yml file , The name of the document is dream21thtomcatservice.yml, The contents of the document are as follows :
apiVersion: apps/v1
kind: Deployment
metadata:
name: dream21th-tomcat-deployment
labels:
app: dream21th-tomcat-deployment
spec:
replicas: 3
template:
metadata:
name: dream21th-tomcat-deployment
labels:
app: dream21th-tomcat
spec:
containers:
- name: dream21th-tomcat-deployment
image: tomcat:9.0.20-jre8-alpine
imagePullPolicy: IfNotPresent
restartPolicy: Always
selector:
matchLabels:
app: dream21th-tomcat
---
apiVersion: v1
kind: Service
metadata:
name: dream21th-tomcat-service
spec:
selector:
app: dream21th-tomcat
ports:
- port: 8888
targetPort: 8080
nodePort: 30089
protocol: TCP
type: NodePort
Execute the following instructions , And verify :
[[email protected] service]# kubectl apply -f dream21thtomcatservice.yml
deployment.apps/dream21th-tomcat-deployment created
service/dream21th-tomcat-service created
[[email protected] service]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dream21th-tomcat-service NodePort 10.96.13.168 <none> 8888:30089/TCP 7s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 119d
[[email protected] service]# kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
dream21th-tomcat-deployment 3/3 3 3 18s
[[email protected] service]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
dream21th-tomcat-deployment-5fc846c9bc-5jhd9 1/1 Running 0 24s 10.244.2.6 k8s-work2 <none> <none>
dream21th-tomcat-deployment-5fc846c9bc-p26kj 1/1 Running 0 24s 10.244.1.12 k8s-work1 <none> <none>
dream21th-tomcat-deployment-5fc846c9bc-xpnd5 1/1 Running 0 24s 10.244.1.11 k8s-work1 <none> <none>
[[email protected] service]# curl 192.168.43.103:30089
Service Parameters and Service type :
port : visit service Port used
targetPort :Pod Container port in
NodePort: adopt Node Realize the access of external network users k8s Within cluster service(30000-32767)
ClusterIP: Default , Assign a virtual machine that can be accessed within the cluster IP
NodePort: At every Node Assign a port on as an external access entry
LoadBalancer: Work in a particular Cloud Provider On , for example Google Cloud,AWS,OpenStack
ExternalName: It refers to the introduction of services outside the cluster into the cluster , That is to realize the cluster inside pod And services outside the cluster communicate
Execute the following instructions to delete the deployed svc and deployment.
[[email protected] service]# kubectl delete -f dream21thtomcatservice.yml
deployment.apps "dream21th-tomcat-deployment" deleted
service "dream21th-tomcat-service" deleted
边栏推荐
- 秒杀系统设计
- Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation
- Leetcode skimming - game 280
- One of the reasons why setinterval timer does not take effect in ie: the callback is the arrow function
- 程序分析与优化 - 9 附录 XLA的缓冲区指派
- 哪些软件可以整篇翻译英文论文?
- Explain in detail the significance of the contour topology matrix obtained by using the contour detection function findcontours() of OpenCV, and how to draw the contour topology map with the contour t
- NC50528 滑动窗口
- Markdown使用教程
- 论文的设计方案咋写?
猜你喜欢

Basic use of shell script

教育学大佬是怎么找外文参考文献的?
![[shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a](/img/f2/f3b8899aa774dd32006c5928d370f1.gif)
[shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a

Cmake basic use

Maya fishing house modeling

Where can I find the English literature of the thesis (except HowNet)?

写论文可以去哪些网站搜索参考文献?
![Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration](/img/a3/55bb71d39801ceeee421a0c8ded333.png)
Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration

Feature Engineering: summary of common feature transformation methods

【单片机项目实训】八路抢答器
随机推荐
来自数砖大佬的 130页 PPT 深入介绍 Apache Spark 3.2 & 3.3 新功能
Andorid 获取系统标题栏高度
字符设备注册常用的两种方法和步骤
Don't want teachers to see themselves with cameras in online classes? Virtual camera you deserve!
Slf4j + logback logging framework
英文论文有具体的格式吗?
How do educators find foreign language references?
Missing number
可下载《2022年中国数字化办公市场研究报告》详解1768亿元市场
多进程编程(三):消息队列
DotNet圈里一个优秀的ORM——FreeSql
maya渔屋建模
[pulsar document] concepts and architecture
[golang syntax] map common errors golang panic: assignment to entry in nil map
Blue decides red - burst CS teamserver password
监控容器运行时工具Falco
sysdig分析容器系统调用
【单片机项目实训】八路抢答器
redis21道经典面试题,极限拉扯面试官
Automated defect analysis in electronic microscopic images