Kubernetes deploy and description - unix1998/technical_notes GitHub Wiki

Kubernetes does not natively support Source-to-Image (S2I) deployment out of the box as OpenShift does. S2I is a feature specific to OpenShift that simplifies the process of building and deploying applications directly from source code. In Kubernetes, you typically use other tools and methods to build and deploy your applications, such as:

  • Docker: Building Docker images locally or in CI/CD pipelines and then pushing them to a container registry.
  • Helm: A package manager for Kubernetes that allows you to define, install, and upgrade complex Kubernetes applications.
  • Kustomize: A tool for customizing Kubernetes configurations.
  • CI/CD Pipelines: Using tools like Jenkins, GitLab CI, or GitHub Actions to automate the build and deployment process.

Kubernetes Configuration Example

In Kubernetes, instead of a single deploy-config.yaml, you would typically have multiple YAML files or a single multi-document YAML file defining different resources such as Deployment, Service, and Ingress. Here’s an example of what a Kubernetes configuration might look like for deploying an application:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: myregistry/myapp:latest
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: myapp.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: myapp
            port:
              number: 80

Explanation of Kubernetes Configuration

  • Deployment: Manages the deployment of your application pods.
    • apiVersion: apps/v1: Specifies the API version.
    • kind: Deployment: Defines the resource type.
    • metadata.name: The name of the deployment.
    • spec.replicas: The number of pod replicas.
    • spec.selector: Labels to identify the pods managed by this deployment.
    • spec.template: The pod template, specifying the container image and ports.
  • Service: Exposes the deployment internally within the Kubernetes cluster.
    • apiVersion: v1: Specifies the API version.
    • kind: Service: Defines the resource type.
    • metadata.name: The name of the service.
    • spec.selector: Labels to match the pods to expose.
    • spec.ports: The service ports and the target ports on the pods.
  • Ingress: Provides external access to the service, typically using HTTP/HTTPS.
    • apiVersion: networking.k8s.io/v1: Specifies the API version.
    • kind: Ingress: Defines the resource type.
    • metadata.name: The name of the ingress.
    • spec.rules: The routing rules for the ingress.

Building and Pushing Images

In Kubernetes, you typically need to build your application image and push it to a container registry. Here’s an example using Docker:

# Build the Docker image
docker build -t myregistry/myapp:latest .

# Push the Docker image to a registry
docker push myregistry/myapp:latest

After pushing the image, you can apply the Kubernetes configuration:

kubectl apply -f deploy-config.yaml

Summary

  • No Native S2I: Kubernetes does not natively support Source-to-Image (S2I). Instead, you build Docker images and deploy them using standard Kubernetes resources.
  • Multiple Resources: Kubernetes configurations typically involve multiple resource definitions (e.g., Deployment, Service, Ingress).
  • Build and Push Images: You need to build Docker images and push them to a container registry manually or through CI/CD pipelines before deploying them to Kubernetes.

By using Kubernetes' standard resources and tools, you can effectively manage and deploy your applications in a flexible and scalable manner.