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:
- Create the chap9 namespace:
$ kubectl create namespace chap9
namespace "chap9" created
- 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
- Create the Pod on the chap9 namespace:
$ kubectl create -f myapp.yaml --namespace=chap9
pod "myapp" created
- Access the GCP Web Console and navigate to Logging | Logs.
- Select Audited Resources | GKE Container | Your GKE cluster name (ex: my-gke) | chap9 namespace:
Selecting the chap9 namespace Pod log
- 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
- Now, you can see the myapp log on Stackdriver:
Showing the chap9 Pod log in Stackdriver