Kubernetes HA data across several workers [closed] - kubernetes

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I have set up a Kubernetes system with 1 Master and 3 worker Nodes, and a load balancer. But at the moment my pipes are stuck as I'm struggling to find a solution, how can I setup a WordPress website with traffic that is replicated on all nodes. All for me is clear only I don't get, how to get all 3 Workers ( VPS servers in different countries) to have the same data so that pods can work and scale, and if one worker is dead the second and third can continue providing all services. IS PVE the solution or some other? Please point me in the direction to start searching.
Thanks.

You can create a PersistentVolumeClaim in ReadWriteMany mode that creates a PersistentVolume that holds your WordPress site data then create a Deployment with 3 replicas that mounts that PersistentVolume.
Example:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-data
spec:
accessModes:
- ReadWriteMany
volumeMode: Filesystem
storageClass: fast # update this to whatever persistent storage class is available on your cluster. See https://kubernetes.io/docs/concepts/storage/storage-classes/
resources:
requests:
storage: 10Gi
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
replicas: 3
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress:latest
ports:
- containerPort: 80
name: http
protocol: TCP
volumeMounts:
- mountPath: "/var/www/html"
name: wordpress-data
volumes:
- name: wordpress-data
persistentVolumeClaim:
claimName: wordpress-data # notice this is referencing the PersistentVolumeClaim we declared above
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
type: NodePort # or LoadBalancer
selector:
app: wordpress
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80

Related

Kubernetes error converting YAML to JSON: yaml: line 30: could not find expected ':' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm starting my journey with kubernetes and i'm stuck with deploying my application.
From my perspective there is no error in the code but seems like kubernetes has diffrent opinion on that.
Please have a look:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mq-pv-claim
labels:
app: mq
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mq-test
labels:
app: mq
spec:
replicas: 2
selector:
matchLabels:
app: mq
template:
metadata:
labels:
app: mq
spec:
containers:
- image: store/ibmcorp/mqadvanced-server-dev:9.1.2.0
name: queue-man
env:
- name: LICENSE
value: accept
- name: MQ_QMGR_NAME
value: QM1
ports:
- containerPort: 1414
volumeMounts:
- name: mqdata
mountPath:/mnt/mqm
volumes:
- name: mqdata
persistentVolumeClaim:
claimName: mq-pv-claim
The error i get is:
error parsing .\mq.yaml: error converting YAML to JSON: yaml: line 30: could not find expected ':'
The line no. 30 is spec: which obviously has got the ':'
The yaml is not properly indented. Below should work.
spec:
containers:
- image: store/ibmcorp/mqadvanced-server-dev:9.1.2.0
name: queue-man
env:
- name: LICENSE
value: accept
- name: MQ_QMGR_NAME
value: QM1
ports:
- containerPort: 1414

Installing a local FTP Server with K8S / Minikube, and accessing it with Filezilla

I'm trying to install a FTP server with Kubernetes based on this repo.
I also use Traefik as Ingress.
Everything seems fine, and I can I connect FTP Server with cluster-ip, but I can't make it work with a local domain like ftp.local
Here are my K8S files:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
reloader.stakater.com/auto: "true"
labels:
app: ftp-local
name: ftp-local
namespace: influx
spec:
selector:
matchLabels:
app: ftp-local
strategy:
type: Recreate
replicas: 1
template:
metadata:
labels:
app: ftp-local
spec:
containers:
- name: ftp-local
image: fauria/vsftpd
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 21
protocol: TCP
name: "ftp-server"
volumeMounts:
- mountPath: "/home/vsftpd"
name: task-pv-storage
env:
- name: FTP_USER
value: "sunchain"
- name: FTP_PASS
value: "sunchain"
#- name: PASV_ADDRESS
# value: "127.0.0.1"
#- name: PASV_MIN_PORT
# value: "21100"
#- name: PASV_MAX_PORT
# value: "21110"
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: task-pv-claim
namespace: influx
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: task-pv-volume
namespace: influx
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp/data"
---
apiVersion: v1
kind: Service
metadata:
name: ftp-local
namespace: influx
labels:
app: ftp-local
spec:
ports:
- name: "21"
port: 21
targetPort: 21
selector:
app: ftp-local
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ftp-ingress
namespace: influx
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: ftp.local
http:
paths:
- backend:
serviceName: ftp-local
servicePort: 21
I also have a line in /etc/hosts that like that:
127.0.0.1 ftp.local
What am I missing ?
At first, link to repo you used was created/updated 2-3 years ago.
Many newest Kubernetes features require SSL for communication. That's the reason why SFTP is easier to apply in Kubernetes.
Another thing, you are using Minikube with --driver=none which have some restrictions. All neccesary information about none driver are described here.
There was already similar question regarding FTP Filezilla in this thread.
As workaround you can consider using hostPort or hostNetwork.
Many configuration aspects depends on if you want to use Acitve or Passive FTP.
FTP requires two TCP connection to work. Second connection is established using random port. I doesn't look compatible with Services concept. SFTP requires only one connection.
As another solution you could consider use SFTP. You can find many articles in the web with information that its better to use SFTP instead of FTP. For example Tibco docs or this article
You can check Information about SFTP server using OpenSSH and try this github SFTP example.
Here you can find information abut using SFTP in FileZilla.

Kubernetes Yaml Generator UI , yaml builder for kubernetes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Is there any tool , online or self hosted , that takes all the values in UI as input and generate the full declarative yaml for the following kubernetes objects:
Deployment, with init containers and imagepullsecrets and other options
Service
ConfigMap
Secret
Daemonset
StatefulSet
Namespaces and quotas
RBAC resources
Edit:
I have been using kubectl create and kubectl run , but they dont spupport all the possible configuration options , and you still need to rememer all the options it supports , in UI one would be able to select from the give options for each resource.
The closest is kubectl create .... and kubectl run ...... Run them with -o yaml --dry-run > output.yaml. This won't create the resource, but will write the resource description to output.yaml file.
Found yipee.io that supports all the options and resources:
# Generated 2018-10-18T11:07:27.621Z by Yipee.io
# Application: nginx
# Last Modified: 2018-10-18T11:07:27.621Z
apiVersion: v1
kind: Service
metadata:
namespace: webprod
name: nginx
spec:
selector:
app: nginx
ports:
- port: 80
targetPort: 8080
name: nginx-hhpt
protocol: TCP
nodePort: 30003
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
namespace: webprod
annotations:
yipee.io.lastModelUpdate: '2018-10-18T11:07:27.595Z'
spec:
selector:
matchLabels:
name: nginx
component: nginx
app: nginx
rollbackTo:
revision: 0
template:
spec:
imagePullSecrets:
- name: imagsecret
containers:
- volumeMounts:
- mountPath: /data
name: nginx-vol
name: nginx
ports:
- containerPort: 80
protocol: TCP
name: http
imagePullPolicy: IfNotPresent
image: docker.io/nginx:latest
volumes:
- name: nginx-vol
hostPath:
path: /data
type: Directory
serviceAccountName: test
metadata:
labels:
name: nginx
component: nginx
app: nginx
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 2
replicas: 1
revisionHistoryLimit: 3
I have tried to address the same issue using a Java client based on the most popular Kubernetes Java Client:
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>4.1.3</version>
</dependency>
It allows you to set the most exotic options... but the API is not very fluent (or I have not found yet the way to use it fluently) so the code becomes quite verbose... Building a UI is a challenge, because of the extreme complexity of the model.
yipee.io sounds promising though, but I didn't understand how to get a trial version.

Kubernetes multi-container pod [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
Hello I try to have a Pod with 2 container, one a c++ app, one a mysql database. I used to have the mysql deployed in its own service, but i got latency issue. So i want to try multi-container pod.
But i've been struggling to connect my app with the mysql through localhost. It says..
Can\'t connect to local MySQL server through socket
\'/var/run/mysqld/mysqld.sock
Here is my kubernetes.yaml. Please I need help :(
# Database setup
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: storage-camera
labels:
group: camera
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-ssd
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: camera-pv
labels:
group: camera
spec:
storageClassName: db-camera
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
storageClassName: storage-camera
---
# Service setup
apiVersion: v1
kind: Service
metadata:
name: camera-service
labels:
group: camera
spec:
ports:
- port: 50052
targetPort: 50052
selector:
group: camera
tier: service
type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: camera-service
labels:
group: camera
tier: service
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
minReadySeconds: 60
template:
metadata:
labels:
group: camera
tier: service
spec:
containers:
- image: asia.gcr.io/test/db-camera:latest
name: db-camera
env:
- name : MYSQL_ROOT_PASSWORD
value : root
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: camera-persistent-storage
mountPath: /var/lib/mysql
- name: camera-service
image: asia.gcr.io/test/camera-service:latest
env:
- name : DB_HOST
value : "localhost"
- name : DB_PORT
value : "3306"
- name : DB_NAME
value : "camera"
- name : DB_ROOT_PASS
value : "password"
ports:
- name: http-cam
containerPort: 50052
volumes:
- name: camera-persistent-storage
persistentVolumeClaim:
claimName: camera-pv
restartPolicy: Always
Your MySQL client is configured to use a socket and not talk over the network stack, cf. the MySQL documentation:
On Unix, MySQL programs treat the host name localhost specially, in a
way that is likely different from what you expect compared to other
network-based programs. For connections to localhost, MySQL programs
attempt to connect to the local server by using a Unix socket file.
This occurs even if a --port or -P option is given to specify a port
number. To ensure that the client makes a TCP/IP connection to the
local server, use --host or -h to specify a host name value of
127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by
using the --protocol=TCP option.
If you still want camera-service to talk over the file system socket you need to mount the file system for the camera-service as well. Currently you only mount it for db-camera

Multiple Kubernetes pods sharing the same host-path/pvc will duplicate output

I have a small problem and need to know what is the best way to approach this/solve my issue.
I have deployed few pods on Kubernetes and so far I have enjoyed learning about and working with Kubernetes. Did all the persistent volume, volume claim...etc. and can see my data on the host, as I need those files for further processing.
Now the issue is 2 pods (2 replicas) sharing the same volume claim are writing to the same location on the host, expected, but unfortunately causing the data to be duplicated in the output file.
What I need is:
To have a unique output of each pod on the host. Is the only way to achieve this is by
having two deployment files, in my case, and each to use a different volume claim/persistent
volume ? At the same time not sure if this is an optimal approach for future updates, upgrades, availability of certain number of pods ... etc.
Or can I still have one deployment file with 2 or more replicas and still avoid the output duplication when sharing the same pvc ?
Please note that I have one node deployment and that's why I'm using hostpath at the moment.
creating pv:
kind: PersistentVolume
apiVersion: v1
metadata:
name: ls-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 100Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/ls-data/my-data2"
claim-pv:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ls-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Gi
How I use my pv inside my deployment:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: logstash
namespace: default
labels:
component: logstash
spec:
replicas: 2
selector:
matchLabels:
component: logstash
#omitted
ports:
- containerPort: 5044
name: logstash-input
protocol: TCP
- containerPort: 9600
name: transport
protocol: TCP
volumeMounts:
- name: ls-pv-store
mountPath: "/logstash-data"
volumes:
- name: ls-pv-store
persistentVolumeClaim:
claimName: ls-pv-claim
Depending on what exactly you are trying to achieve you could use Statefulsets instead of Deployments. Each Pod spawn from the Statefulset's Pod template can have it's own separate PersistentVolumeClaim that is created from the volumeClaimTemplate (see the link for an example). You will need a StorageClass set up for this.
If you are looking for something simpler you write to /mnt/volume/$HOSTNAME from each Pod. This will also ensure that they are using separate files as the hostnames for the Pods are unique.