Kubernetes: Creating Objects

Create resource(s) in a JSON or YAML file

kubectl create -f ./file.yml
kubectl create -f ./file1.yml -f ./file2.yaml

Create resources in all .json, .yml, and .yaml files in dir

kubectl create -f ./dir

Create from a URL

kubectl create -f http://www.fpaste.org/279276/48569091/raw/

Create multiple YAML objects from stdin

cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
  name: busybox-sleep
spec:
  containers:
  - name: busybox
    image: busybox
    args:
    - sleep
    - "1000000"
---
apiVersion: v1
kind: Pod
metadata:
  name: busybox-sleep-less
spec:
  containers:
  - name: busybox
    image: busybox
    args:
    - sleep
    - "1000"
EOF

Create a secret with several keys

cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  password: $(echo "s33msi4" | base64)
  username: $(echo "jane" | base64)
EOF

Leave a Reply

Your email address will not be published. Required fields are marked *