Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include all kubernetes objects into one file

Assuming I have two multi-container pods and services for exposing the pods to the cluster. I also have Replication controller for maintaining the number of pods at any time.

The above cluster is an trivial example. In this point I have two pod files, two service files and two RC files. This makes the file management difficult.

I know that all the files can be put in a directory and use kubectl create -f directory to execute whole thing in a single command. But, I feel the file management is a overhead. Is there something like docker-compose.yml, where we can include all pods in a single file.

I would like to know the best practices for using kubernetes in production. Changing many files in production does not seem to be an good idea.

like image 841
Lakshman Diwaakar Avatar asked Dec 08 '16 08:12

Lakshman Diwaakar


People also ask

Where are all Kubernetes objects stored?

Configuration files are typically stored in source control, such as Git. live object configuration / live configuration: The live configuration values of an object, as observed by the Kubernetes cluster. These are kept in the Kubernetes cluster storage, typically etcd.

What is a Kubernetes manifest file?

The Kubernetes manifest is a JSON configuration file that describes the list of Kubernetes versions supported by HPE Ezmeral Runtime Enterprise, Kubernetes add-on versions, and specific container image version dependencies that are relevant during the installation of a Kubernetes cluster.

Do containers in a pod share filesystem?

Containers within same pod share network namespace and IPC namespace but they have separate mount namespace and filesystem.


1 Answers

You can use triple dashes or List resource as in these examples:

  • List
  • Triple Dashes

examples:

List

apiVersion: v1
kind: List
items:
- apiVersion: v1
  kind: Service
  metadata:
    name: list-service-test
  spec:
    ports:
    - protocol: TCP
      port: 80
    selector:
      app: list-deployment-test
- apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: list-deployment-test
    labels:
      app: list-deployment-test
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          app: list-deployment-test
      spec:
        containers:
          - name: nginx
            image: nginx

Triple dash:

---
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: redis
    redis-sentinel: "true"
    role: master
  name: redis-master
spec:
  containers:
    - name: master
      image: kubernetes/redis:v1
      env:
        - name: MASTER
          value: "true"
      ports:
        - containerPort: 6379
      resources:
        limits:
          cpu: "0.5"
      volumeMounts:
        - mountPath: /redis-master-data
          name: data
    - name: sentinel
      image: kubernetes/redis:v1
      env:
        - name: SENTINEL
          value: "true"
      ports:
        - containerPort: 26379
  volumes:
    - name: data
      emptyDir: {}
---
apiVersion: v1
kind: Pod
metadata:
  labels:
    name: redis-proxy
    role: proxy
  name: redis-proxy
spec:
  containers:
  - name: proxy
    image: kubernetes/redis-proxy:v1
    ports:
    - containerPort: 6379
      name: api
like image 130
Ivan Frolov Avatar answered Oct 18 '22 05:10

Ivan Frolov