Skip to content

K8s courses

kube config fodler

./kube
./kube/deployment.yml
./kube/namespace.yml
./kube/service.yml
./kube/ingress.yml

deployment.yml

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
  namespace: my-namespace
  labels:
    app: my-app

spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: my-image
        imagePullPolicy: Never # Never for local development 
        ports:
        - containerPort: 80

namespace.yml

yaml
apiVersion: apps/v1
kind: namespace
metadata:
  name: my-namespace

service.yml

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
  namespace: my-namespace
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80

ingress.yml

yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  namespace: my-namespace
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - host: my-host
    http:
      paths:
      - path: /my/path
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              number: 8080

Apply

sh
kubectl apply -f ./kube/namespace.yml
kubectl apply -f ./kube/deployment.yml
kubectl apply -f ./kube/service.yml
kubectl apply -f ./kube/ingress.yml

Horizontal pods auto scaler