i have created a pvc.yaml file but i am not able to add pvc to cluster as, i am facing a error for pvc.yaml file.
My pvc.yaml file content :
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-device-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
after creating pvc i am using the cmd below ---*
kubctl create -f pvc.yaml
error message after cmd is ---
error
error: error parsing pvc.yaml: error converting YAML to JSON: yaml: line 8: could not find expected ':'
i have used online yaml validater but still i am unable to solve this error.
i want my yaml file to be created and solve ther error syntax error: could not find expected ':'
Related
I'm not able to create node group using yaml file inside yaml file it contains bootstrap.sh to create node group, here the file
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: ginny
region: us-west-2
version: '1.17'
managedNodeGroups:
- name: ginny-mng-custom-ami
instanceType: t3.small
desiredCapacity: 2
labels: {role: worker}
ami: ami-0030109261aa0205b
ssh:
publicKeyName: bastion
preBootstrapCommands:
- kubelet --version > /etc/eks/test-preBootstrapCommands
overrideBootstrapCommand: |
#!/bin/bash
set -ex
/etc/eks/bootstrap.sh ginny --kubelet-extra-args "--node-labels=alpha.eksctl.io/cluster-name=ginny,alpha.eksctl.io/nodegroup-name=ginny-mng-custom-ami,eks.amazonaws.com/nodegroup=ginny-mng-custom-ami,eks.amazonaws.com/nodegroup-image=ami-0030109261aa0205b"
[root#ip-1-2-3-4 eks-node-group]# eksctl create nodegroup --config-file maanged-nodegroup.yaml
Error: couldn't create node group filter from command line options: loading config file "maanged-nodegroup.yaml": error converting YAML to JSON: yaml: line 15: mapping values are not allowed in this context
Try this way It should work:
preBootstrapCommands:
- kubelet --version > /etc/eks/test-preBootstrapCommands
overrideBootstrapCommand: |
#!/bin/bash
set -ex
/etc/eks/bootstrap.sh ginny --kubelet-extra-args "--node-labels=alpha.eksctl.io/cluster-name=ginny,alpha.eksctl.io/nodegroup-name=ginny-mng-custom-ami,eks.amazonaws.com/nodegroup=ginny-mng-custom-ami,eks.amazonaws.com/nodegroup-image=ami-0030109261aa0205b"
I'm trying to install a Helm chart, but I'm receiving errors from an annotation
annotations: {}
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "true"
helm.go:84: [debug] error converting YAML to JSON: yaml: line **: did not find expected key
code fast with www.microapi.io
Remove {}
annotations:
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "true"
I have an application.yml (Spring) file, which has almost 70 fields, want to move those fields to ConfigMap.
In the process of setup ConfigMap, have realized all the 70 fields has be flatened example : webservice.endpoint.transferfund
It's gonna be a painful task to convert all the 70 fields as flat, is there any alternative.
Please suggest.
Below Config is working:
apiVersion: v1
kind: ConfigMap
metadata:
name: configmapname
namespace: default
data:
webservice.endpoint.transferfund: http://www.customer-service.app/api/tf
webservice.endpoint.getbalance: http://www.customer-service.app/api/balance
webservice.endpoint.customerinfo: http://www.customer-service.app/api/customerinfo
Below config is not working, tried it as yml format.
apiVersion: v1
kind: ConfigMap
metadata:
name: configmapname
namespace: default
data:
application.yaml: |-
webservice:
endpoint:
transferfund: http://www.customer-service.app/api/tf
getbalance: http://www.customer-service.app/api/balance
customerinfo: http://www.customer-service.app/api/customerinfo
in src/main/resources/application.yml have below fields to access ConfigMap keys:
webservice:
endpoint:
transferfund: ${webservice.endpoint.transferfund}
getbalance: ${webservice.endpoint.getbalance}
customerinfo: ${webservice.endpoint.customerinfo}
Updated:
ConfigMap Description:
C:\Users\deskktop>kubectl describe configmap configmapname
Name: configmapname
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
application.yaml:
----
webservice:
endpoint:
transferfund: http://www.customer-service.app/api/tf
getbalance: http://www.customer-service.app/api/balance
customerinfo: http://www.customer-service.app/api/customerinfo
Events: <none>
Deployment script: (configMapRef name provided as configmap name as shown above)
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: configmap-sample
spec:
replicas: 1
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: configmap-sample
spec:
containers:
- name: configmap-sample
image: <<image>>
ports:
- name: http-api
containerPort: 9000
envFrom:
- configMapRef:
name: configmapname
resources:
limits:
memory: 1Gi
requests:
memory: 768Mi
env:
- name: JVM_OPTS
value: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -Xms768M"
A ConfigMap is a dictionary of configuration settings. It consists of key-value pairs of strings. Kubernetes then adds those values to your containers.
In your case you have to make them flat, because Kubernetes will not understand them.
You can read in the documentation about Creating ConfigMap that:
kubectl create configmap <map-name> <data-source>
where is the name you want to assign to the ConfigMap and is the directory, file, or literal value to draw the data from.
The data source corresponds to a key-value pair in the ConfigMap, where
key = the file name or the key you provided on the command line, and
value = the file contents or the literal value you provided on the command line.
You can use kubectl describe or kubectl get to retrieve information about a ConfigMap.
EDIT
You could create a ConfigMap from a file with defined key.
Define the key to use when creating a ConfigMap from a file
Syntax might look like this:
kubectl create configmap my_configmap --from-file=<my-key-name>=<path-to-file>
And the ConfigMap migh look like the following:
apiVersion: v1
kind: ConfigMap
metadata:
creationTimestamp: 2019-07-03T18:54:22Z
name: my_configmap
namespace: default
resourceVersion: "530"
selfLink: /api/v1/namespaces/default/configmaps/my_configmap
uid: 05f8da22-d671-11e5-8cd0-68f728db1985
data:
<my-key-name>: |
key=value
key=value
key=value
key=value
Also I was able to find Create Kubernetes ConfigMaps from configuration files.
Functionality
The projector can:
Take raw files and stuff them into a ConfigMap
Glob files in your config repo, and stuff ALL of them in your configmap
Extract fields from your structured data (yaml/json)
Create new structured outputs from a subset of a yaml/json source by pulling out some fields and dropping others
Translate back and forth between JSON and YAML (convert a YAML source to a JSON output, etc)
Support for extracting complex fields like objects+arrays from sources, and not just scalars!
You need to mount the ConfigMap as Volume. Otherwise the content would live in environment variables. The example i post here is from https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "ls /etc/config/" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: special-config
restartPolicy: Never
You mentioned, you're using the application.yaml in context of a Spring project. So if you don't care whether you use .yaml or .property configuration-files, you can just use property-files because configMap generation supports them. It works with the --from-env-file flag:
kubectl create configmap configmapname --from-env-file application.properties
So in your deployment-file you can directly access the keys:
...
env:
- KEYNAME
valueFrom:
configMapKeyRef:
name: configmapname
key: KeyInPropertiesFile
I am using below yaml file to create the pod, kubectl command giving below error.
How to correct this error message?
apiVersion: v1
kind: Pod
metadata:
name: command-demo
labels:
purpose: demonstrate-command
spec:
containers:
- name: command-demo-container
image: debian
command: ["printenv"]
args: ["HOSTNAME", "KUBERNETES_PORT"]
env:
- name: MESSAGE
value: "hello world"
command: ["/bin/echo"]
args: ["$(MESSAGE)"]
kubectl create -f commands.yaml
error: error validating "commands.yaml": error validating data: found invalid field env for v1.PodSpec; if you choose to ignore these errors, turn validation off with --validate=false
follow example from this page.
https://kubernetes.io/docs/tasks/configure-pod-container/define-command-argument-container/
Thanks
-SR
Your—syntactically correct—YAML results in an incorrect data-structure for kubernetes. In YAML the indentations can affect the structure of the data. See this.
I think this should be correct:
apiVersion: v1
kind: Pod
metadata:
name: command-demo
labels:
purpose: demonstrate-command
spec:
containers:
- name: command-demo-container
image: debian
command: ["printenv"]
args: ["HOSTNAME", "KUBERNETES_PORT"]
env:
- name: MESSAGE
value: "hello world"
command: ["/bin/echo"]
args: ["$(MESSAGE)"]
I have configured filebeat for logstash. But while starting the filebeat I am getting following error :
main.go:42: CRIT Config error: Error reading config file: YAML config parsing failed on /etc/filebeat/filebeat.yml: yaml: unmarshal errors:
line 2: cannot unmarshal !!str `paths:
...` into []config.ProspectorConfig. Exiting.
I have configured filebeat on other server with same configuration and there it is working perfectly but I don't understand why am I getting this syntax error on this server.
Here is the configuration file :
filebeat:
prospectors: |-
paths:
'/var/log/*.log'
registry_file: /var/lib/filebeat/registry
config_dir: /etc/filebeat/conf.d
output:
elasticsearch:
enabled: false
hosts:
- 52.35.55.85:9200
logstash:
enabled: true
hosts:
- 52.32.18.237:5044
file:
enabled: false
path: /tmp/filebeat
filename: filebeat
rotate_every_kb: 1000
number_of_files: 7
I don't know anything about filebeat (or even Go, really), but this error message:
cannot unmarshal !!str `paths:
...` into []config.ProspectorConfig. Exiting.
...suggests to me that it's expecing the paths value to be a sequence (YAML parlance for array), not a scalar (string). Instead of this:
paths:
'/var/log/*.log'
...try this:
paths:
- '/var/log/*.log'
...or, since the quotes are extraneous here:
paths:
- /var/log/*.log