Compose
  • 1. metadata
  • 2. spec
  • 3. status
  • Deployment
  • Pods from the same deployment have the same labels
  • Selector uses the labels to know which pods belong to the deployment
  • Pod label, selector label in deployment, deployment label, and service label should be same
  • Service uses the labels to create connection
  • Names are used as the reference, can be arbitrary names
  • apiVersion: apps/v1
    kind: Deployment # type
    metadata:
      name: nginx-deployment # deployment name
      labels:
        app: nginx
    spec: # specification for deployment
      replicas: 1 # number of replicas
      selector:
        matchLabels:
          app: nginx
      template: # specification for pods
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.16
            ports:
            - containerPort: 8080 # container access port
            
    Service
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx-service
    spec:
      selector:
        app: nginx
      ports:
        - protocol: TCP
          port: 80 # service port
          targetPort: 8080 # container port
            
    Secret
    apiVersion: v1
    kind: Secret
    metadata:
      name: mongo-secret
    type: Opaque
    data:
      mongo-user: bW9uZ291c2Vy
      mongo-password: bW9uZ29wYXNzd29yZA==
            
    Ingress

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: minimal-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      ingressClassName: nginx-example
      rules:
      - http:
          paths:
          - path: /testpath
            pathType: Prefix
            backend:
              service:
                name: test
                port:
                  number: 80
            
    Reference
  • Command-line tools for Kubernetes: kubectl, stern, kubectx, kubens
  • Kubernetes best practices: Organizing with Namespaces