Kubernetes yaml创建服务
2019-03-27 本文已影响0人
济南打工人
Pod
apiVersion: extensions/v1beta1 ← 使用的对象描述规范版本
kind: Deployment ← 对象类型为Deployment
metadata:
name: frontend ← 生成Deployment对象的名称
namespace: test ← Pod所在的命名空间
spec:
replicas: 3 ← 其中包含3个Pod副本
template: ← 这是每个Pod副本的模板
metadata:
labels: ← 每个副本都具有两个标识标签
app: frontend
tier: frontend
spec:
containers: ← Pod中的容器列表
- name: php-redis
image: images.antlinker.com/test/antbas:500
resources: ← 该容器所需资源的描述
requests:
cpu: 100m
memory: 100Mi
env: ← 声明该容器中的环境变量
- name: GET_HOSTS_FROM
value: dns
ports: ← 声明该容器中使用的端口
- containerPort: 8099
volumeMounts:
- name: time ← 挂载本地目录
mountPath: /etc/localtime
- name: redis-vo ← 挂载ConfigMapap文件
mountPath: /etc/redis ← 配置文件挂载的位置
volumes:
- name: time ← 定义本地挂载目录名称
hostPath:
path: /etc/localtime ← 本地路径
- name: antbas-vo ← ConfigMap文件
configMap:
name: redis-cfg
nodeSelector: ← 只有此标签的Node节点才能创建
server: server
Service
apiVersion: v1 ← 使用的对象描述规范版本
kind: Service ← 对象类型为Service
metadata:
name: frontend ← 生成该Service对象的名称
labels: ← 该Service对象具有的标签
app: frontend
tier: frontend
namespace: test ← 该Service所在的命名空间
spec:
ports: ← 被选中Pod需要对外暴露的端口
- port: 80
protocol: UDP ← 端口所使用的协议
selector: ← 选择后端Pod的标签依据
app: frontend
tier: frontend
服务配置文件
apiVersion: v1 ← 使用的对象描述规范版本
kind: ConfigMap ← 对象类型为ConfigMap
metadata:
name: redis-vo ← 生成该ConfigMap的名称
namespace: test ← 该服务所在的命名空间
data:
redis.conf: | ← 该服务的文件名
... ← 文件内容
...
...