k8s常用命令创建yaml文件
时间: 2023-08-02 18:11:36 浏览: 39
以下是一些常用的 kubernetes 命令和示例 yaml 文件:
1. 创建 Deployment:
```
kubectl create deployment nginx-deployment --image=nginx
```
对应的 yaml 文件:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
```
2. 创建 Service:
```
kubectl create service clusterip nginx-service --tcp=80:80
```
对应的 yaml 文件:
```yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: ClusterIP
selector:
app: nginx
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
```
3. 创建 ConfigMap:
```
kubectl create configmap nginx-config --from-literal=nginx-version=1.19.1
```
对应的 yaml 文件:
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
nginx-version: "1.19.1"
```
4. 创建 Secret:
```
kubectl create secret generic db-secret --from-literal=username=admin --from-literal=password=passw0rd
```
对应的 yaml 文件:
```yaml
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
username: YWRtaW4=
password: cGFzc3cwcmQ=
```
以上仅是一些示例,具体的 yaml 文件格式和内容需要根据实际场景进行调整。