Pod的定义
apiVersion: v1
kind: Pod # 类型定义为Pod
metadata:
name: nginx # 定义Pod的name
labels:
app: nginx # 用来给选择器筛选一组具有相同的label的Pod
spec:
containers:
- name: nginx
image: nginx # Pod运行的镜像
ports:
- containerPort: 80 # Docker容器暴露的端口
Service的定义
apiVersion: v1
kind: Service # 类型为Service
metadata:
name: nginx # 定义Service的name
spec:
ports:
- port: 8078 # the port that this service should serve on, service暴露在cluster ip上的端口
name: http
# the container on each pod to connect to, can be a name
# (e.g. 'www') or a number (e.g. 80)
targetPort: 80 # targetPort是pod上的端口
protocol: TCP
selector:
app: nginx # 选择-l app=nginx(标签中有app:nginx)的Pod
Deployment的定义
apiVersion: extensions/v1beta1
kind: Deployment # 类型为Deployment
metadata:
name: nginx-deployment # 定义Deployment的name
spec:
replicas: 3 # 副本数量
template: # 表示使用的部署模板信息(Pod)
metadata:
labels:
app: nginx # 定义Pod的Label(-l app=nginx)
spec:
containers: # 定义Pod的Container信息
- name: nginx # 定义Pod的name
image: nginx:1.7.9 # 定义Pod的镜像
ports:
- containerPort: 80 # 定义Pod的端口
Namespace的定义
apiVersion: v1
kind: Namespace # 类型为Namespace
metadata:
name: gateway # 创建gateway命名空间
ConfigMap的定义
apiVersion: v1
kind: ConfigMap # 类型为ConfigMap
metadata:
name: special-config # 配置的name
namespace: default # 配置所在命名空间
data:
special.how: very # special["how"]="very"
special.type: charm # special["type"]="charm"
PersistentVolume的定义
apiVersion: v1
kind: PersistentVolume # 类型为ConfigMap
metadata:
name: pv0003 # PV的name
spec:
capacity:
storage: 5Gi # PV的容量
accessModes:
- ReadWriteOnce # PV的访问权限
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /tmp # 使用的nfs目录
server: 172.17.0.2 # 使用的nfs host
与对象创建相关的命令
kubectl create -f xxxx.yaml
根据文件创建定义的对象(或者多个对象)
kubectl apply -f xxxx.yaml
根据文件更新定义的对象