Deploying a Stand-Alone Application

$ minikube dashboard

Imgur

Imgur

Imgur

Imgur Imgur

NOTE: Add the full URL in the Container Image field docker.io/library/nginx:alpine if any issues are encountered with the simple nginx:alpine image name (or use the k8s.gcr.io/nginx:alpine URL if it works instead)

Display details

Imgur

Imgur

Imgur

Imgur

List the Pods, along with their attached Labels

$ kubectl get pods -L k8s-app,blabla NAME READY STATUS RESTARTS AGE K8S-APP BLABLA webserver-c8f4d5fbc-9j65j 1/1 Running 0 42m webserver webserver-c8f4d5fbc-hm9xt 1/1 Running 0 42m webserver webserver-c8f4d5fbc-mlzc9 1/1 Running 0 42m webserver

Select the Pods with a given Label

$ kubectl get pods -l k8s-app=webserver NAME READY STATUS RESTARTS AGE webserver-c8f4d5fbc-9j65j 1/1 Running 0 48m webserver-c8f4d5fbc-hm9xt 1/1 Running 0 48m webserver-c8f4d5fbc-mlzc9 1/1 Running 0 48m
$ kubectl get pods -l k8s-app=webserver1 No resources found in default namespace.

Delete the Deployment

$ kubectl delete deploy webserver deployment.apps "webserver" deleted
$ kubectl get replicasets No resources found in default namespace.
$ kubectl get pods No resources found in default namespace.

Deploy application using CLI.

$ kubectl create deploy --help Create a deployment with the specified name. Aliases: deployment, deploy Examples: # Create a new deployment named my-dep that runs the busybox image. kubectl create deployment my-dep --image=busybox Options: --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats. --dry-run=false: If true, only print the object that would be sent, without sending it. --generator='': The name of the API generator to use. --image=[]: Image name to run. -o, --output='': Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file. --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --validate=true: If true, use a schema to validate the input before sending it Usage: kubectl create deployment NAME --image=image [--dry-run] [options] Use "kubectl options" for a list of global command-line options (applies to all commands).
$ kubectl create deploy webserver --image=nginx:alpine -o yaml --dry-run=true > webserver.yaml $ kubectl get deploy No resources found in default namespace.
$ cat webserver.yaml apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: webserver name: webserver spec: replicas: 1 selector: matchLabels: app: webserver strategy: {} template: metadata: creationTimestamp: null labels: app: webserver spec: containers: - image: nginx:alpine name: nginx resources: {} status: {}
$ cat webserver.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: nginx name: webserver spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx:alpine name: nginx ports: - containerPort: 80
$ kubectl create -f webserver.yaml deployment.apps/webserver created
$ kubectl get deploy,rs,pods NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/webserver 3/3 3 3 62s NAME DESIRED CURRENT READY AGE replicaset.apps/webserver-5c559d5697 3 3 3 62s NAME READY STATUS RESTARTS AGE pod/webserver-5c559d5697-7bz8p 1/1 Running 0 62s pod/webserver-5c559d5697-c5ncg 1/1 Running 0 62s pod/webserver-5c559d5697-rlb26 1/1 Running 0 62s
$ kubectl create service --help Create a service using specified subcommand. Aliases: service, svc Available Commands: clusterip Create a ClusterIP service. externalname Create an ExternalName service. loadbalancer Create a LoadBalancer service. nodeport Create a NodePort service. Usage: kubectl create service [flags] [options] Use "kubectl <command> --help" for more information about a given command. Use "kubectl options" for a list of global command-line options (applies to all commands).
$ kubectl create service nodeport web-service --tcp=80 --dry-run=true -o yaml > webserver-svc.yaml
$ cat webserver-svc.yaml apiVersion: v1 kind: Service metadata: labels: run: web-service name: web-service spec: ports: - port: 80 protocol: TCP selector: app: nginx type: NodePort
$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h44m
$ kubectl create -f webserver-svc.yaml service/web-service created
$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h45m web-service NodePort 10.100.52.43 <none> 80:30387/TCP 23s
$ kubectl expose deployment webserver --port=81 --target-port=80 --type=NodePort
$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h54m web-service NodePort 10.100.52.43 <none> 80:30387/TCP 8m57s webserver NodePort 10.107.217.161 <none> 81:31838/TCP 16s
$ kubectl describe service web-service Name: web-service Namespace: default Labels: run=web-service Annotations: <none> Selector: app=nginx Type: NodePort IP: 10.100.52.43 Port: <unset> 80/TCP TargetPort: 80/TCP NodePort: <unset> 30387/TCP Endpoints: 172.17.0.4:80,172.17.0.5:80,172.17.0.6:80 Session Affinity: None External Traffic Policy: Cluster Events: <none>
$ kubectl describe node minikube | grep IP InternalIP: 192.168.99.101
$ kubectl describe services web-service | grep NodePort Type: NodePort NodePort: <unset> 30387/TCP
$ minikube ip 192.168.99.101
$ minikube service web-service |-----------|-------------|-------------|-----------------------------| | NAMESPACE | NAME | TARGET PORT | URL | |-----------|-------------|-------------|-----------------------------| | default | web-service | | http://192.168.99.101:30387 | |-----------|-------------|-------------|-----------------------------| * Opening service default/web-service in default browser...

Liveness and Readiness Probes.

Liveness

Liveness : Command

Liveness HTTP Request

livenessProbe: httpGet: path: /healthz port: 8080 httpHeaders: - name: X-Custom-Header value: Awesome initialDelaySeconds: 3 periodSeconds: 3

TCP Liveness Probe

livenessProbe: tcpSocket: port: 8080 initialDelaySeconds: 15 periodSeconds: 20

Readiness Probs