1、创建pod的基础文件
- 创建pod的yaml文件详解
---
apiVersion: extensions/v1beta1 #当前格式的版本
kind: Deployment #当前创建资源的类型, 当前类型是Deployment
metadata: #当前资源的元数据name: test-os #当前资源的名字 是元数据必须的项
spec: #是当前Deployment的规格说明replicas: 1 #指当前创建的副本数量 默认不填 默认值就为‘1’template: #定义pod的模板metadata: #当前pod的元数据labels: #至少顶一个labels标签,可任意创建一个 key:valueapp: test_osspec: #当前pod的规格说明containers: #容器- name: centos #是容器的名字容器名字是必须填写的image: harbor.soft72.com:8080/public/myos:latest #镜像 镜像的名字和版本imagePullPolicy: IfNotPresent #镜像在宿主机上不存在时才拉取stdin: truetty: true
---
apiVersion: v1
kind: Service #指定资源类型
metadata: name: web-service #指定service的名称namespace: default
spec:clusterIP: 10.254.254.110 #指定service的集群IP,自己可以规划,只能在集群内访问(pod内做负载)ports:- port: 80 #指定service前端端口targetPort: 80 #指定目标端口,即容器的服务端口,nodePort:protocol: TCPselector:app: web #指定服务的名字type: ClusterIP
cat web-service.yaml
apiVersion: v1
kind: Service
metadata:name: nginx-servicenamespace: kube-public
spec:clusterIP: 10.254.254.110ports:- port: 88 #clusterip的端口targetPort: 80 #pod的端口nodePort: 30002 #映射到kube-node的端口protocol: TCPselector:app: nginx-labtype: NodePort
- kubectl命令
如何使用资源文件
使用资源文件管理对象- [x] kubectl (apply | create | delete) -f 资源文件- [x] create 创建资源对象、apply 升级更新资源对象- [x] delete 删除资源对象
[root@kube-master ~]# kubectl create -f baseos.yaml
[root@kube-master ~]# kubectl delete -f baseos.yaml
2、configmap映射
2.1、ConfigMap定义
ConfigMap 用于解决容器内的配置文件更新修改的问题- [x] 获取 httpd.conf, 并做出相应的修改- [x] 创建 configmap- [x] kubectl create configmap 名称 --from-file=文件路径
使用拷贝的文件 httpd.conf,创建一个 configmap,名称为 my-httpd
[root@kube-master files]# kubectl create configmap my-httpd --from-file=/root/files/httpd.conf
># httpd.conf是已经修改过的文件
2.2、参数详解
---
apiVersion: extensions/v1beta1 #当前格式的版本
kind: Deployment #当前创建资源的类型, 当前类型是Deployment
metadata: #当前资源的元数据name: web-test #当前资源的名字 是元数据必须的项
spec: #是当前Deployment的规格说明replicas: 1 #指当前创建的副本数量 默认不填 默认值就为‘1’template: #定义pod的模板metadata: #当前pod的元数据labels: #至少顶一个labels标签,可任意创建一个 key:valueapp: web-testspec: #当前pod的规格说明containers: #容器- name: web-test #是容器的名字容器名字是必须填写的image: 192.168.1.100:5000/myos:httpd #镜像 镜像的名字和版本ports:- containerPort: 8080 #声明容器端口号volumeMounts:- mountPath: /var/webroot #目标路径name: site-data #引用卷映射定义 (自定义名称,相当于是标识ID)- mountPath: /etc/httpd/conf/httpd.conf #映射完全路径name: my-config #引用卷映射定义 (自定义名称,相当于是标识ID)subPath: httpd.conf #目标文件名volumes:- name: site-dataemptyDir: {}- name: my-config #定义卷资源名称configMap:name: my-httpd #引用的 configmap 配置名(kubectl create configmap 创建的)items:- key: httpd.confpath: httpd.conf
创建
[root@kube-master ~]# kubectl create -f configmap.yaml
练习