How to set SMTP (email configration) in .yaml file in kubernetes - kubernetes

I want to deploy ghost (blog) on Kubernetes with email configuration in google cloud.
ghost is running fine in k8s. But, I'm not able to fix my SMTP setting in deployment file
my .yaml file
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: blog
labels:
app: blog
spec:
replicas: 1
selector:
matchLabels:
app: blog
template:
metadata:
labels:
app: blog
spec:
containers:
- name: blog
image: ghost:2.6-alpine
imagePullPolicy: Always
ports:
- containerPort: 2368
env:
- name: url
value: http://my-blog.com
environment:
url: http://my-blog.com
mail__transport: 2525
mail__options__service: {Sendgrid}
mail__options__auth__user: "gurpreet004"
mail__options__auth__pass: "Server#1234"
it showing an error :
error: error validating "deployment.yaml": error validating data: ValidationError(Deployment.spec.template): unknown field "environment" in io.k8s.api.core.v1.PodTemplateSpec; if you choose to ignore these errors, turn validation off with --validate=false
please provide any solution

The environment field doesn't exist. If you want these values as environment variables in the container, you can do like this:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: blog
labels:
app: blog
spec:
replicas: 1
selector:
matchLabels:
app: blog
template:
metadata:
labels:
app: blog
spec:
containers:
- name: blog
image: ghost:2.6-alpine
imagePullPolicy: Always
ports:
- containerPort: 2368
env:
- name: url
value: http://my-blog.com
- name: mail__transport
value: SMTP
- name: mail__options__service
value: Sendgrid
- name: mail__options__auth__user
value: gurpreet004
- name: mail__options__auth__pass
value: Server#1234

The given answer is correct but you need to follow some steps:
. Create the account in the Mailgun.
. verify the account and also register your domain.
. Mailgun provides you with "demo SMTP" details to test your mail.
. if you need you can reset your (demo SMTP)password.
. Enter these details in the mail section of yours.YAML file and run it.
. Open ghost admin and click the option "labs"-> test mail

Related

I have one deployment.yaml file if I am trying to deploy it in kubernetes by the command kubectl apply -f then it is throwing resource not found error

I am unable to deploy this file by using
kubectl apply -f command
Deployment YAML image
I have provided the YAML file required for your deployment. It is important that all the lines are indented correctly. Hyphens (-) indicate a list item. Therefore, it is not required to use them on every line.
apiVersion: apps/v1
kind: Deployment
metadata:
name: abc-deployment
namespace: abc
spec:
replicas: 3
selector:
matchLabels:
app: abc-deployment
template:
metadata:
labels:
app: abc-deployment
spec:
containers:
- name: abc-deployment
image: anyimage
ports:
- containerPort: 80
env:
- name: APP_VERSION
value: v1
- name: ENVIRONMENT
value: "123"
- name: DATA
valueFrom:
configMapKeyRef:
name: abc-configmap
key: data
imagePullPolicy: IfNotPresent
restartPolicy: Always
imagePullSecrets:
- name: abc-secret
As a side note, the way envFrom was used is incorrect. It must be within the container env section, and formatted as such in the example above (see the DATA env variable).
If you are using Visual Studio Code, there is an official Kubernetes extension from Microsoft that provides Intellisense (suggestions) and alerts you to errors.
Hope this helps.

Wiremock docker add OAUTH2

I am using WireMock docker image to mock an endpoint. I am using the below yaml to create a deployment on kubernetes and it's working fine, I have added __files and mappings to add the endpoints and responses. Now I need to add OAUTH2 to test authentication in my application. could this be done? and what properties should I add:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wiremock-helper
labels:
app: wiremock-helper
spec:
replicas: 1
selector:
matchLabels:
app: wiremock-helper
template:
metadata:
labels:
app: wiremock-helper
spec:
containers:
- name: wiremock-helper
image: rodolpheche/wiremock:latest
ports:
- containerPort: 8080
volumeMounts:
- name: wiremock-volume
mountPath: /home/wiremock
volumes:
- name: wiremock-volume
nfs:
server: 10.0.0.0
path: /home/wiremock
I'm not certain I understand your question, but if I do, the deployment won't handle Authentication or Authorization. You can have your application handle those directly, use an API gateway/proxy solution (envoy, emissary-ingress, traefik, ory oathkeeper, etc.), or use a service mesh solution (Istio with Auth Policy).

Kubernetes :Validation Error(Deployment.spec.template.spec.container[0]): unknown field "ConfigMapref" in io.k8s.api.core.v1.Container

I am doing my first deployment in Kubernetes and I've hosted my API in my namespace and it's up and running. So I tried to connect my API with MongoDB. Added my database details in ConfigMaps via Rancher.
I tried to invoke the DB in my deployment YAML file but got an error stating Unknown Field - ConfigMapref
Below is my deployment YAML file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myfistproject
namespace: Owncloud
spec
replicas: 2
selector:
matchLables:
app: myfirstproject
version: 1.0.0
template:
metadata:
labels:
app: myfirstproject
version: 1.0.0
spec:
containers:
- name: myfirstproject
image: **my image repo location**
imagePullPolicy: always
ports:
- containerPort: 80
configMapRef:
- name: myfirstprojectdb # This is the name of the config map created via rancher
myfirstprojectdb ConfigMap will store all the details like the database name, username, password, etc.
On executing the pipeline I get the below error.
How do I need to refer my config map in deployment yaml?
Validation Error(Deployment.spec.template.spec.container[0]): unknown field "ConfigMapref" in io.k8s.api.core.v1.Container
There are some more typos (e.g. missing : after spec or Always should be with capital letter). Also indentation should be consistent in the whole yaml file - see yaml indentation and separation.
I corrected your yaml so it passes api server's check + added config map reference (considering it contains env variables):
apiVersion: apps/v1
kind: Deployment
metadata:
name: myfistproject
namespace: Owncloud
spec:
replicas: 2
selector:
matchLabels:
app: myfirstproject
version: 1.0.0
template:
metadata:
labels:
app: myfirstproject
version: 1.0.0
spec:
containers:
- name: myfirstproject
image: **my image repo location**
imagePullPolicy: Always
ports:
- containerPort: 80
envFrom:
- configMapRef:
name: myfirstprojectdb
Useful link:
Configure all key-value pairs in a ConfigMap as container environment variables which is related to this question.

k8s `selector` does not match template `labels`

I am pulling my hair out here. I deployed my template, deleted it, and then I go to deploy it again without any changes and am getting the following error:
The Deployment "blog" is invalid: spec.template.metadata.labels: Invalid value: map[string]string(nil): selector does not match template labels
My deployment yaml is below and as you can see the metadata and selector labels are both web, so I have no idea what the error is trying to tell me:
apiVersion: apps/v1
kind: Deployment
metadata:
name: blog
labels:
app: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
replicas: 1
template:
spec:
containers:
- env:
image: test_blog:latest
imagePullPolicy: Always
name: blog
ports:
- containerPort: 8080
You have two template block. I think thats the problem. Try this.
apiVersion: apps/v1
kind: Deployment
metadata:
name: blog
labels:
app: web
spec:
selector:
matchLabels:
app: web
replicas: 1
template:
metadata:
labels:
app: web
spec:
containers:
- env:
image: test_blog:latest
imagePullPolicy: Always
name: blog
ports:
- containerPort: 8080

kubernetes set env variable

My requirement is inside pod there is a file
location : /mnt/secrets-store/environment
In kubernetes manifest file i would like to set environment variable . Values contains above location flat file
pls share your thought how to achieve that
I have tried below option in the k8s yml file but not working
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-api
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: sample-api
template:
metadata:
labels:
app: sample-api
aadpodidbinding: azure-pod-identity-binding-selector
spec:
containers:
- name: sample-api
image: sample.azurecr.io/sample:11129
imagePullPolicy: Always
ports:
- containerPort: 80
env:
- name: "ASPNETCORE_ENVIRONMENT"
value: "Kubernetes"
- name: NRIA_DISPLAY_NAME
value: $("/usr/bin/cat" "/mnt/secrets-store/environment")