首页 技术 正文
技术 2022年11月9日
0 收藏 828 点赞 3,838 浏览 2831 个字
apiVersion: v1 #指定api版本,此值必须在kubectl apiversion中
kind: Deployment #指定创建资源的角色/类型
metadata: #资源的元数据/属性
name: my-pod #资源的名字,在同一个namespace中必须唯一
namespace: devlopment
labels: #设定资源的标签
k8s-app: my-pod
version: v1
kubernetes.io/cluster-service: "true"
annotations: #自定义注解列表
- name: String #自定义注解名字
spec:#specification of the resource content 指定该资源的内容
#replicas: 3 # 副本数,在与hpa一起使用是千万不要开启此功能,影响容器资源获取,滚动更新策略
revisionHistoryLimit: 15 #保留历史版本数量,如果不写数据会一直保留在etcd中,没有必要。
#minReadySeconds: 5 # 一下为更新策略 , 默认即可,不要填写
#strategy:
# type: RollingUpdate
# rollingUpdate:
# maxSurge: 3
# maxUnavailable: 2
template:
metadata:
labels:
k8s-app: my-pod
nodeSelector: #节点选择,先给主机打标签kubectl label nodes kube-node1 zone=node1
zone: node1
restartPolicy: Always #表明该容器一直运行,默认k8s的策略,在此容器退出后,会立即创建一个相同的容器
    spec:
serviceAccount: default #服务权限相关
    containers:
- name: my-container #容器的名字
image: image:tag #容器使用的镜像地址
imagePullPolicy: Never #三个选择Always、Never、IfNotPresent,每次启动时检查和更新(从registery)images的策略,
# Always,每次都检查
# Never,每次都不检查(不管本地是否有)
# IfNotPresent,如果本地有就不检查,如果没有就拉取
command: ['sh'] #启动容器的运行命令,将覆盖容器中的Entrypoint,对应Dockefile中的ENTRYPOINT
args: ["$(str)"] #启动容器的命令参数,对应Dockerfile中CMD参数
env: #指定容器中的环境变量 ,从ConfigMap或secrit中获取
- name: key #变量的名字
value: value #变量的值
resources: #资源管理
requests: #容器运行时,最低资源需求,也就是说最少需要多少资源容器才能正常运行
cpu: 0.1 #CPU资源(核数),两种方式,浮点数或者是整数+m,0.1=100m,最少值为0.001核(1m)
memory: 32Mi #内存使用量
limits: #资源限制
cpu: 0.5
memory: 32Mi
ports:
- containerPort: # 容器开放对外的端口
targetPort: # 外部访问端口
#nodePort: # 映射到实体机端口,不需指定自动分配
name: httpd #名称
protocol: TCP
livenessProbe: #pod内容器健康检查的设置
httpGet: #通过httpget检查健康,返回200-399之间,则认为容器正常
path: / #URI地址
port:
#host: 127.0.0.1 #主机地址
scheme: HTTP
initialDelaySeconds: #表明第一次检测在容器启动后多长时间后开始
timeoutSeconds: #检测的超时时间
periodSeconds: #检查间隔时间
#也可以用这种方法
#exec: 执行命令的方法进行监测,如果其退出码不为0,则认为容器正常
# command:
# - cat
# - /tmp/health
#也可以用这种方法
#tcpSocket: //通过tcpSocket检查健康
# port: number readinessProbe: #pod内容器对外提供服务检测的设置
    httpGet:
exec:
tcpSocket: lifecycle: #生命周期管理
postStart: #容器运行之前运行的任务
exec:
command:
- 'sh'
- 'yum upgrade -y'
preStop:#容器关闭之前运行的任务
exec:
command: ['service httpd stop']
#有数据持久话需求时 volumeMounts: #TODO PersistentVolume Claim
- name: volume #挂载设备的名字,与volumes[*].name 需要对应
mountPath: /data #挂载到容器的某个路径下
readOnly: True
volumes: #定义一组挂载设备
- name: volume #定义一个挂载设备的名字
#meptyDir: {}
hostPath: # 宿主机
path: /opt #挂载设备类型为hostPath,路径为宿主机下的/opt,这里设备类型支持很多种
nfs: #nfs 服务
server: 192.168.6.1
path: "/data/nfs"
#-name:my-container2 第二个容器---
apiVersion: v1
kind: Service #指定创建资源的角色/类型
metadata: #元数据管理配置
name: my-service
namespace: devlopment
spec: #服务端口号配置
ports:
- port:
targetPort:
name: web
- port:
targetPort:
name: admin
selector: #应用选择器配置
k8s-app: my-pod
#type: NodePort
---
apiVersion: extensions/v1beta1
kind: Ingress #指定创建资源的角色/类型
metadata: #元数据管理配置
name: my-ingress
namespace: default
spec:
rules: #访问规则配置
- host: test.myaddress.com #访问域名
http:
paths:
- path: / #匹配路径
backend: #对应的后端服务
serviceName: my-service #服务名称
servicePort:  #服务的端口号
- path: /admin
backend:
serviceName: my-service
servicePort: #TODO Configmap 配置文件管理
#https://www.jianshu.com/p/571383da7adf
#TODO Secrit 安全敏感信息管理
https://www.jianshu.com/p/530b3642c642
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294