NAME¶
Podman-Kube-Generate-基于容器、Pod或卷生成Kubernetes YAML
SYNOPSIS¶
podman kube generate [options] container... | pod... | volume...
DESCRIPTION¶
podman kube generate 从Podman容器、Pod或卷生成Kubernetes YAML(v1规范)。无论输入是针对容器还是针对Pod,Podman都会默认将规范作为Pod生成。输入可以是一个或多个容器、豆荚或卷名或ID的形式。
Podman Containers or Pods
卷根据两种不同的卷类型显示在生成的YAML中。绑定装载的卷将变为 hostPath 卷类型和命名卷变为 persistentVolumeClaim 卷类型。生成 hostPath 卷类型是三种子类型之一,具体取决于主机路径的状态: DirectoryOrCreate 当主机上不存在文件或目录时, Directory 当主机路径为目录时,或 File 当主机路径为文件时。的值 claimName 对于一个 persistentVolumeClaim 是在Podman中注册的命名卷的名称。
通过对每种卷类型使用标准命名方案,可以避免卷之间潜在的名称冲突。这个 主机路径 卷类型根据主机上的路径命名,将正斜杠替换为连字符减去任何前导和尾随正斜杠。文件系统根目录的特殊情况, /
,翻译成这个名字 root
。此外,该名称后缀为 -host
要避免命名与冲突,请执行以下操作 持久化卷声明 音量。每个 持久化卷声明 卷类型使用其关联命名卷的名称,后缀为 -pvc
。
请注意,如果使用类型创建初始化容器 once
并且Pod已经启动,它不会在生成的Kube YAML中显示为 once
类型初始化容器在运行后被删除。如果Pod仅已创建且未启动,则它位于生成的Kube YAML中。使用类型创建的初始化容器 always
始终在Kube YAML中生成,因为它们永远不会被删除,即使在运行到完成之后也是如此。
Note :使用卷并为上的非特权和无根Podman容器生成Kubernetes YAML 支持SELinux的系统 ,必须完成以下选项之一:
将“Privileged:True”选项添加到Pod规范
添加
type: spc_t
在securityContext
seLinuxOptions
在Pod规范中通过CLI命令重新标记卷
chcon -t container_file_t -R <directory>
完成后,在Kubernetes集群中创建实例/容器时,访问卷的权限就正确了。
请注意,生成的Kubernetes YAML文件可用于通过podman-play-Kube(1)重新运行部署。
请注意,如果正在生成的Pod是使用 --infra-name 标志设置,则生成的Kube YAML将具有 io.podman.annotations.infra.name 设置值是用户设置的inra容器的名称的位置。
另请注意,部署和DaemonSet只能具有 restartPolicy
设置为 Always
。
OPTIONS¶
--filename , -f = filename¶
输出到给定文件,而不是STDOUT。如果该文件已经存在, kube generate
拒绝替换并返回错误。
--podman-only¶
在生成的YAML文件中添加仅Podman保留的注释(Kubernetes不能使用)
--replicas , -r = replica count¶
要设置的值 replicas
在生成 Deployment 善良。注意:此选项只能使用选项进行设置 --type=deployment
。
--service , -s¶
除了Pods之外,还生成一个Kubernetes服务对象。用于为相应的Pod输出生成服务规范。具体地说,如果对象具有端口映射绑定,则服务规范包括一个用于公开服务的NodePort声明。Podman在规范中分配了一个随机端口。
--type , -t = pod | deployment | daemonset¶
要在YAML文件中生成的Kubernetes类型。目前,唯一支持的Kubernetes规范是 Pod
, Deployment
和 DaemonSet
。默认情况下, Pod
将生成规范。
EXAMPLES¶
为指定容器创建Kubernetes Pod YAML。
$ podman kube generate some-mariadb
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-4.8.2
# NOTE: If you generated this yaml from an unprivileged and rootless podman container on an SELinux
# enabled system, check the podman generate kube man page for steps to follow to ensure that your pod/container
# has the right permissions to access the volumes added.
---
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2024-01-09T02:24:55Z"
labels:
app: some-mariadb-pod
name: some-mariadb-pod
spec:
containers:
- args:
- mariadbd
env:
- name: MARIADB_ROOT_PASSWORD
value: x
image: docker.io/library/mariadb:10.11
name: some-mariadb
ports:
- containerPort: 3306
hostPort: 34891
volumeMounts:
- mountPath: /var/lib/mysql
name: mariadb_data-pvc
volumes:
- name: mariadb_data-pvc
persistentVolumeClaim:
claimName: mariadb_data
为指定容器创建3个副本的Kubernetes部署YAML。
$ podman kube generate --type deployment --replicas 3 dep-ct
r
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-4.5.0-dev
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: "2023-03-27T20:45:08Z"
labels:
app: dep-ctr-pod
name: dep-ctr-pod-deployment
spec:
replicas: 3
selector:
matchLabels:
app: dep-ctr-pod
template:
metadata:
annotations:
io.podman.annotations.ulimit: nofile=524288:524288,nproc=127332:127332
creationTimestamp: "2023-03-27T20:45:08Z"
labels:
app: dep-ctr-pod
name: dep-ctr-pod
spec:
containers:
- command:
- top
image: docker.io/library/alpine:latest
name: dep-ctr
使用host目录为指定的容器创建Kubernetes Pod YAML /home/user/my-data
绑定挂载到容器路径 /volume
。
$ podman kube generate my-container-with-bind-mounted-data
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-3.1.0-dev
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2021-03-18T16:26:08Z"
labels:
app: my-container-with-bind-mounted-data
name: my-container-with-bind-mounted-data
spec:
containers:
- command:
- /bin/sh
image: docker.io/library/alpine:latest
name: test-bind-mount
volumeMounts:
- mountPath: /volume
name: home-user-my-data-host
restartPolicy: Never
volumes:
- hostPath:
path: /home/user/my-data
type: Directory
name: home-user-my-data-host
使用命名卷为指定容器创建Kubernetes Pod YAML priceless-data
安装在集装箱路径上 /volume
。
$ podman kube generate my-container-using-priceless-data
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-3.1.0-dev
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2021-03-18T16:26:08Z"
labels:
app: my-container-using-priceless-data
name: my-container-using-priceless-data
spec:
containers:
- command:
- /bin/sh
image: docker.io/library/alpine:latest
name: test-bind-mount
volumeMounts:
- mountPath: /volume
name: priceless-data-pvc
restartPolicy: Never
volumes:
- name: priceless-data-pvc
persistentVolumeClaim:
claimName: priceless-data
为指定实例创建Kubernetes Pod YAML并包含服务。
$ sudo podman kube generate -s demoweb
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#
# Created with podman-0.12.2-dev
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: 2018-12-18T15:16:06Z
labels:
app: demoweb
name: demoweb-libpod
spec:
containers:
- command:
- python3
- /root/code/graph.py
image: quay.io/baude/demoweb:latest
name: practicalarchimedes
tty: true
workingDir: /root/code
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: 2018-12-18T15:16:06Z
labels:
app: demoweb
name: demoweb-libpod
spec:
ports:
- name: "8050"
nodePort: 31269
port: 8050
targetPort: 0
selector:
app: demoweb
type: NodePort
status:
loadBalancer: {}
另请参阅¶
podman(1) , podman-container(1) , podman-pod(1) , podman-kube-play(1) , podman-kube-down(1)
HISTORY¶
2018年12月,最初由布伦特·鲍德(Brent Baude)汇编(在redhat.com网站上bbaude)