Kubernetes yaml kind types Explained

Kubernetes yaml kind types Explained

This article will introduce kubernetes yaml kind types and how examples of how they are used. Kubernetes is a container orchestration system for automating software development. When you deploy resources you can use either the kubectl command line or make life easier and build a yaml file. Inside of that file you you have what are called kind types such as:

  • Pod
  • Deployment
  • Service
  • Configmap
  • Secret

Yaml files require strict indentation. Its best to use an editor that has a built in yaml validator such as visual studio code.

Overview of Kubernetes YAML kind types

Kubernetes uses the YAML (Yet Another Markup Language) format for defining the configuration of objects in a cluster. A kubernetes kind type is a type of object that you can create, such as a Deployment or a Service.

An example of the types of kubernetes yaml kind types specified in the yaml file are:

  • Pod: A Pod is the smallest unit of deployment in Kubernetes. It is a logical host for one or more containers, which are the lowest level of compute in Kubernetes. Pods run on nodes, which are the physical machines in a cluster.
  • Deployment: Deployments are logical collections of one or more replicas of a particular application. Deployments help ensure that the specified number of replicas are always running and automatically replaces any replicas that fail or are deleted.
  • Service: A Service is an abstraction that defines a group of pods and a policy for accessing them. Services allow you to access your application using a consistent, stable IP address and DNS name, regardless of which underlying pods are running.
  • Configmap: Configmaps allow you to store non sensitive data in a key value store to be accessed my multiple resources. Think of this as a way to create variables
  • Secret: Secretes give you a way to store encrypted passwords, tokens, or certificates. They are only decrypted when requested

Kubernetes YAML kind types examples

The difficult part of writing kubernetes yaml files are the strict indentation requirements and remembering what goes into each type. As an IT professional it can be very difficult to remember everything you come across. Reading Kubernetes documentation can give you a great start on whats needed in each file.

Here are examples of each of the service types listed above that can be used and kept as templates.

Kubernetes Pod Yaml File Example

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
  - port: <Port>
    targetPort: <Target Port>

Kubernetes Deployment Yaml File Example

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: <Image>
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: <Port>

Kubernetes Service Yaml File Example

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
  - port: <Port>
    targetPort: <Target Port>

Kubernetes Configmap Yaml File Example

apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp
data:
  key: value

Kubernetes Configmap Yaml File Example

apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  password: <Password>

Edit these files and to fit your environment. Across all the examples, apiVersion, kind, and metadata are standard across each file type.

Conclusion

When creating kubernetes services, you will come across kubernetes yaml file types you may not have worked with. Finding examples and keeping them as templates will help with deployments across your clusters. Visit the kubernetes website for further documentation on all the resources

Comments are closed.