How to do it...

In order to demonstrate Stackdriver with GKE, we will create one namespace on Kubernetes, then launch a sample Pod to see some logs on the Stackdriver, as shown in the following steps:

  1. Create the chap9 namespace:
$ kubectl create namespace chap9
namespace "chap9" created
  1. Prepare a sample application Pod:
$ cat myapp.yaml 
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- image: busybox
name: application
args:
- /bin/sh
- -c
- >
while true; do
echo "$(date) INFO hello";
sleep 1;
done
  1. Create the Pod on the chap9 namespace:
$ kubectl create -f myapp.yaml --namespace=chap9
pod "myapp" created
  1. Access the GCP Web Console and navigate to Logging | Logs.
  2. Select Audited Resources | GKE Container | Your GKE cluster name (ex: my-gke) | chap9 namespace:
Selecting the chap9 namespace Pod log
  1. As an alternative way of accessing the chap9 namespace log, you can select an advanced filter. Then, type the following criteria to the text field and click the Submit Filter button:
Using an advanced filter
resource.type="container" 
resource.labels.cluster_name="<Your GKE name>"
resource.labels.namespace_id="chap9"
Input an advanced filter criterion
  1. Now, you can see the myapp log on Stackdriver:
Showing the chap9 Pod log in Stackdriver
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.88.157