kubectl_create
Differences
This shows you the differences between two versions of the page.
| kubectl_create [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadm | kubectl_create [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== kubectl create ====== | ||
| - | ===== Todatas as opções ===== | ||
| - | <file bash> | ||
| - | $ kubectl create --help | ||
| - | Create a resource from a file or from stdin. | ||
| - | JSON and YAML formats are accepted. | ||
| - | |||
| - | Examples: | ||
| - | # Create a pod using the data in pod.json | ||
| - | kubectl create -f ./pod.json | ||
| - | |||
| - | # Create a pod based on the JSON passed into stdin | ||
| - | cat pod.json | kubectl create -f - | ||
| - | |||
| - | # Edit the data in registry.yaml in JSON then create the resource using the edited data | ||
| - | kubectl create -f registry.yaml --edit -o json | ||
| - | |||
| - | Available Commands: | ||
| - | clusterrole | ||
| - | clusterrolebinding | ||
| - | configmap | ||
| - | cronjob | ||
| - | deployment | ||
| - | ingress | ||
| - | job | ||
| - | namespace | ||
| - | poddisruptionbudget | ||
| - | priorityclass | ||
| - | quota | ||
| - | role Create a role with single rule | ||
| - | rolebinding | ||
| - | secret | ||
| - | service | ||
| - | serviceaccount | ||
| - | token | ||
| - | |||
| - | Options: | ||
| - | --allow-missing-template-keys=true: | ||
| - | If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to | ||
| - | | ||
| - | |||
| - | --dry-run=' | ||
| - | Must be " | ||
| - | | ||
| - | |||
| - | --edit=false: | ||
| - | Edit the API resource before creating | ||
| - | |||
| - | --field-manager=' | ||
| - | Name of the manager used to track field ownership. | ||
| - | |||
| - | -f, --filename=[]: | ||
| - | | ||
| - | |||
| - | -k, --kustomize='': | ||
| - | | ||
| - | |||
| - | -o, --output='': | ||
| - | | ||
| - | | ||
| - | |||
| - | --raw='': | ||
| - | Raw URI to POST to the server. | ||
| - | |||
| - | -R, --recursive=false: | ||
| - | | ||
| - | | ||
| - | |||
| - | --save-config=false: | ||
| - | If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will | ||
| - | be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. | ||
| - | |||
| - | -l, --selector='': | ||
| - | | ||
| - | | ||
| - | |||
| - | --show-managed-fields=false: | ||
| - | If true, keep the managedFields when printing objects in JSON or YAML format. | ||
| - | |||
| - | --template='': | ||
| - | | ||
| - | is golang templates [http:// | ||
| - | |||
| - | --validate=' | ||
| - | Must be one of: strict (or true), warn, ignore (or false). | ||
| - | the input and fail the request if invalid. It will perform server side validation if ServerSideFieldValidation | ||
| - | is enabled on the api-server, but will fall back to less reliable client-side validation if not. " | ||
| - | warn about unknown or duplicate fields without blocking the request if server-side field validation is enabled | ||
| - | on the API server, and behave as " | ||
| - | | ||
| - | |||
| - | --windows-line-endings=false: | ||
| - | Only relevant if --edit=true. Defaults to the line ending native to your platform. | ||
| - | |||
| - | Usage: | ||
| - | kubectl create -f FILENAME [options] | ||
| - | |||
| - | Use " | ||
| - | Use " | ||
| - | </ | ||
| - | |||
| - | ===== Namespace ===== | ||
| - | <file bash> | ||
| - | $ kubectl create namespace ns-system --dry-run=client -o yaml > ns.yaml | ||
| - | </ | ||
| - | |||
| - | <file yaml ns.yaml> | ||
| - | apiVersion: v1 | ||
| - | kind: Namespace | ||
| - | metadata: | ||
| - | creationTimestamp: | ||
| - | name: ns-system | ||
| - | spec: {} | ||
| - | status: {} | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl create -f ns.yaml | ||
| - | namespace/ | ||
| - | </ | ||
| - | |||
| - | ===== Secret ===== | ||
| - | <file bash secret-app> | ||
| - | POSTGRES_USER=zabbix | ||
| - | POSTGRES_PASSWORD=zabbix | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl create secret generic secret-app -n ns-system --from-env-file=secret-app -o yaml --dry-run=client > secret-app.yaml | ||
| - | </ | ||
| - | |||
| - | <file yaml secret-app.yaml> | ||
| - | apiVersion: v1 | ||
| - | data: | ||
| - | POSTGRES_PASSWORD: | ||
| - | POSTGRES_USER: | ||
| - | kind: Secret | ||
| - | metadata: | ||
| - | creationTimestamp: | ||
| - | name: secret-app | ||
| - | namespace: ns-system | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl create -f secret-app.yaml | ||
| - | secret/ | ||
| - | </ | ||
| - | |||
| - | ===== configMap ===== | ||
| - | <file bash> | ||
| - | $ kubectl create configmap cm-app --from-literal ENABLE_TIMESCALEDB=true -o yaml --dry-run=client > cm-app.yaml | ||
| - | </ | ||
| - | |||
| - | <file yaml cm-app.yaml> | ||
| - | apiVersion: v1 | ||
| - | data: | ||
| - | ENABLE_TIMESCALEDB: | ||
| - | kind: ConfigMap | ||
| - | metadata: | ||
| - | creationTimestamp: | ||
| - | name: cm-app | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl create -f cm-app.yaml | ||
| - | configmap/ | ||
| - | </ | ||
| - | |||
| - | ===== Deployment ===== | ||
| - | <file bash> | ||
| - | $ kubectl create deployment pgsql-server -n ns-system --image=postgres --port=5432 > --dry-run=client -o yaml > deploy-pgsql.yaml | ||
| - | </ | ||
| - | |||
| - | <file yaml deploy-pgsql.yaml> | ||
| - | apiVersion: apps/v1 | ||
| - | kind: Deployment | ||
| - | metadata: | ||
| - | creationTimestamp: | ||
| - | generation: 1 | ||
| - | labels: | ||
| - | app: pgsql-server | ||
| - | name: pgsql-server | ||
| - | namespace: ns-system | ||
| - | resourceVersion: | ||
| - | uid: a3086bc8-6869-42a5-81f8-28e9738c86cf | ||
| - | spec: | ||
| - | progressDeadlineSeconds: | ||
| - | replicas: 1 | ||
| - | revisionHistoryLimit: | ||
| - | selector: | ||
| - | matchLabels: | ||
| - | app: pgsql-server | ||
| - | strategy: | ||
| - | rollingUpdate: | ||
| - | maxSurge: 25% | ||
| - | maxUnavailable: | ||
| - | type: RollingUpdate | ||
| - | template: | ||
| - | metadata: | ||
| - | creationTimestamp: | ||
| - | labels: | ||
| - | app: pgsql-server | ||
| - | spec: | ||
| - | containers: | ||
| - | - image: postgres | ||
| - | imagePullPolicy: | ||
| - | name: postgres | ||
| - | ports: | ||
| - | - containerPort: | ||
| - | protocol: TCP | ||
| - | resources: {} | ||
| - | terminationMessagePath: | ||
| - | terminationMessagePolicy: | ||
| - | dnsPolicy: ClusterFirst | ||
| - | restartPolicy: | ||
| - | schedulerName: | ||
| - | securityContext: | ||
| - | terminationGracePeriodSeconds: | ||
| - | status: {} | ||
| - | </ | ||
| - | |||
| - | <file bash> | ||
| - | $ kubectl create -f deploy-pgsql.yaml | ||
| - | deployment.apps/ | ||
| - | </ | ||
| - | |||
| - | ===== Service ===== | ||
| - | <file bash> | ||
| - | $ kubectl expose deploy pgsql-server --port=5432 --target-port=5432 --type=ClusterIP -n ns-system --dry-run=client -o yaml > svc-app.yaml | ||
| - | </ | ||
| - | |||
| - | <file yaml svc-app.yaml> | ||
| - | apiVersion: v1 | ||
| - | kind: Service | ||
| - | metadata: | ||
| - | creationTimestamp: | ||
| - | labels: | ||
| - | app: pgsql-server | ||
| - | name: pgsql-server | ||
| - | namespace: ns-system | ||
| - | spec: | ||
| - | ports: | ||
| - | - port: 5432 | ||
| - | protocol: TCP | ||
| - | targetPort: 5432 | ||
| - | selector: | ||
| - | app: pgsql-server | ||
| - | type: ClusterIP | ||
| - | status: | ||
| - | loadBalancer: | ||
| - | </ | ||
kubectl_create.1753560544.txt.gz · Last modified: by wikiadm
