Kubernetes Yaml Samples - HaymonEdmur/DockerConfiguration GitHub Wiki


Pod

apiVersion: v1
kind: Pod
metadata:
  name: sales-tomcat-pod
  labels:
    Environment: Development
    Application: Sales
    City: Boston
    State: Massachusetts
spec:
  containers:
    - name: tomcat-container
      image: tomcat
      env:
        - name: DEMO_GREETING
          value: "Hello from the environment"
        - name: DEMO_FAREWELL
          value: "Such a sweet sorrow"
      ports:
       - containerPort: 8080
         name: rest1
         protocol: TCP

Service

apiVersion: v1
kind: Service
metadata:
  name: boston-sales
spec:
  ports:
    - port: 8080
# rest1 is the name of port in Pod yaml file
      targetPort: rest1
  type: NodePort
  selector:
      Environment: Development
      Application: Sales
      City: Boston
      State: Massachusetts

Pod with local volume

kind: Pod
apiVersion: v1
metadata:
  namespace: default
  name: my-nginx-pod
  labels:
    app-region: production
    app-name: FFMS
spec:
  volumes:
    - name: my-html-pages
      hostPath:
        path: /tmp/my-pages
  containers:
    - name: my-nginx-engine
      image: nginx:1.14
      imagePullPolicy: IfNotPresent
      resources:
        limits:
          memory: "20Mi"
          cpu: "1"
        requests:
          memory: "10Mi"
          cpu: "0.5"
      volumeMounts:
        - mountPath: /my-pages
          name: my-html-pages