Como gerar o modelo yaml com o comando kubectl?
é possível gerar o yaml com o comando kubernetes kubectl ? para esclarecer - eu não estou falando sobre gerar yaml a partir de implementações existentes como kubectl get XXXX-o yaml, mas meramente sobre a geração yamls pela primeira vez para pod, serviço, entrada, etc.
PS há uma maneira de obter arquivos yaml de kubernetes.io local ( 1 , 2 ) mas eu estou olhando se há uma maneira de gerar modelos yamls apenas com kubectl.
2 answers
Há o comando create
em kubectl
que faz o truque e substituiu o run
usado no passado: vamos imagem que você deseja criar um Implantação executando um nginx:mais recentes janela de Encaixe imagem.
# kubectl create deployment my_deployment --image=busybox --dry-run=client --output=yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: my_deployment
name: my_deployment
spec:
replicas: 1
selector:
matchLabels:
app: my_deployment
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: my_deployment
spec:
containers:
- image: busybox
name: busybox
resources: {}
status: {}
Vamos analisar cada parâmetro.
-
my_deployment
é o nome que escolheste--image
é a imagem do acoplador que você quer implantar--dry-run=client
não executará a criação de recursos, usada principalmente para validação. Substituir o 'cliente' por 'true' para versões mais antigas do Kubernetes.--output=yaml
imprime para a saída padrão {[12] } A definição YAML do recursode implantação .
Obviamente, poderá executar estas opções apenas com poucos recursos predefinidos do Kubernetes:
# kubectl create
clusterrole Create a ClusterRole.
clusterrolebinding Create a ClusterRoleBinding for a particular ClusterRole
configmap Create a configmap from a local file, directory or literal value
deployment Create a deployment with the specified name.
job Create a job with the specified name.
namespace Create a namespace with the specified name
poddisruptionbudget Create a pod disruption budget with the specified name.
priorityclass Create a priorityclass with the specified name.
quota Create a quota with the specified name.
role Create a role with single rule.
rolebinding Create a RoleBinding for a particular Role or ClusterRole
secret Create a secret using specified subcommand
service Create a service using specified subcommand.
serviceaccount Create a service account with the specified name
De acordo com isto, você pode renderizar o modelo sem a necessidade prévia de implantar o seu recurso.
Também kubectl explain
pode ser usado para diferentes recursos. Ele não irá gerar um arquivo yaml para um pod padrão, mas irá exibir uma descrição para um, por exemplo:
kubectl explain pods
Para obter detalhes de uma secção / propriedade na cápsula:
kubectl explain pods.spec
Também se pode enviar a explicação resultante para um ficheiro yaml e editar isso:
kubectl explain pods > mypod.yaml
E!
com
kubectl explain pod --recursive
Obtém-se toda a estrutura de um recurso sem a explicação; a exportação para um ficheiro yaml pode representar um esqueleto vazio para o recurso pretendido; por baixo de um segmento para o pod:
KIND: Pod
VERSION: v1
DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts.
FIELDS:
apiVersion <string>
kind <string>
metadata <Object>
annotations <map[string]string>
clusterName <string>
creationTimestamp <string>
deletionGracePeriodSeconds <integer>
deletionTimestamp <string>
finalizers <[]string>
generateName <string>
generation <integer>
labels <map[string]string>
managedFields <[]Object>
apiVersion <string>
fieldsType <string>
fieldsV1 <map[string]>
manager <string>
operation <string>
time <string>
name <string>
namespace <string>
ownerReferences <[]Object>
apiVersion <string>
blockOwnerDeletion <boolean>
controller <boolean>
kind <string>
name <string>
uid <string>
resourceVersion <string>
selfLink <string>
uid <string>
spec <Object>
activeDeadlineSeconds <integer>
affinity <Object>
nodeAffinity <Object>
preferredDuringSchedulingIgnoredDuringExecution <[]Object>
preference <Object>
matchExpressions <[]Object>
key <string>
operator <string>
values <[]string>
matchFields <[]Object>
key <string>
operator <string>
values <[]string>
weight <integer>
requiredDuringSchedulingIgnoredDuringExecution <Object>
nodeSelectorTerms <[]Object>
matchExpressions <[]Object>
key <string>
operator <string>
values <[]string>
matchFields <[]Object>
key <string>
operator <string>
values <[]string>
podAffinity <Object>
preferredDuringSchedulingIgnoredDuringExecution <[]Object>
podAffinityTerm <Object>
labelSelector <Object>
matchExpressions <[]Object>
key <string>
operator <string>
values <[]string>
matchLabels <map[string]string>
namespaces <[]string>
topologyKey <string>
weight <integer>
requiredDuringSchedulingIgnoredDuringExecution <[]Object>
labelSelector <Object>
matchExpressions <[]Object>
key <string>
operator <string>
values <[]string>
matchLabels <map[string]string>
namespaces <[]string>
topologyKey <string>
podAntiAffinity <Object>
preferredDuringSchedulingIgnoredDuringExecution <[]Object>
podAffinityTerm <Object>
labelSelector <Object>
matchExpressions <[]Object>
key <string>
operator <string>
values <[]string>
.
.
.