使用vagrant搭建k8s节点四---使用yaml文件部署
Posted lovoo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用vagrant搭建k8s节点四---使用yaml文件部署相关的知识,希望对你有一定的参考价值。
1、生成deployment类型yaml
kubectl create deployment tomcat6 --image=tomcat:6.0.53-jre8 --dry-run -o yaml > tomcat6.yaml
cat tomcat6.yaml
1.1、删除空内容后
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: tomcat6
name: tomcat6
spec:
replicas: 3
selector:
matchLabels:
app: tomcat6
template:
metadata:
labels:
app: tomcat6
spec:
containers:
- image: tomcat:6.0.53-jre8
name: tomcat
1.2、运行删除无效信息后的yaml文件
kubectl apply -f tomcat6.yaml
#查看
kubectl get all
2、生成pot类型yaml
kubectl get pods
获得tomcat名称
输出到mypod.yaml文件中
kubectl get pods tomcat6-5f7ccf4cb9-2xrnr -o yaml > mypod.yaml
删除无效信息得到如下:
apiVersion: v1
kind: Pod
metadata:
labels:
app: tomcat6-1
name: tomcat6-1
namespace: default
spec:
containers:
- image: tomcat:6.0.53-jre8
imagePullPolicy: IfNotPresent
name: tomcat6-1
- image: nginx
imagePullPolicy: IfNotPresent
name: nginx-1
生成pod
kubectl apply -f mypod.yaml
3、生成service类型yaml
生成yaml
kubectl expose deployment tomcat6 --port=80 --target-port=8080 --type=NodePort --dry-run -o yaml > myservice.yaml
cat myservice.yaml
如:
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: tomcat6
name: tomcat6
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: tomcat6
type: NodePort
status:
loadBalancer: {}
将其合成到 tomcat6.yaml 中,使用 "—"线段 分隔
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: tomcat6
name: tomcat6
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: tomcat6
type: NodePort
status:
loadBalancer: {}
[root@k8s-node1 k8s]# vi tomcat6.yaml
[root@k8s-node1 k8s]# vi tomcat6.yaml
[root@k8s-node1 k8s]# cat tomcat6.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: tomcat6
name: tomcat6
spec:
replicas: 3
selector:
matchLabels:
app: tomcat6
template:
metadata:
labels:
app: tomcat6
spec:
containers:
- image: tomcat:6.0.53-jre8
name: tomcat
---
apiVersion: v1
kind: Service
metadata:
labels:
app: tomcat6
name: tomcat6
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: tomcat6
type: NodePort
部署
kubectl apply -f tomcat6.yaml
发现创建 deployment 与 service被创建
分布式技术QQ群:722865146
分布式商城下载:https://gitee.com/charlinchenlin/wysmall
以上是关于使用vagrant搭建k8s节点四---使用yaml文件部署的主要内容,如果未能解决你的问题,请参考以下文章