Table of Content
K8s on Google Cloud
There are two type of ways to run k8s cluster in Google Cloud:
- GCE Google Compute Engine, need to create vm as workstation, install k8s then run script to build up k8s cluster(1 master vm + n worker vm)
- GKE Google Kubernetes Engine, it directly build up k8s cluster, k8s downloaded to vm1 then install from it but all details hidden
gcloud install
You can use Google Cloud Shell for all cloud related activities, also can install gcloud SDK to local workstation, this is example for win7.
C:\Users\oldhorse\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin λ gcloud init Welcome! This command will take you through the configuration of gcloud. Your current configuration has been set to: [default] You can skip diagnostics next time by using the following flag: gcloud init --skip-diagnostics
λ gcloud config list project
project = k8s-miniguide Your active configuration is: [default]
Make sure that gcloud is set to use the Google Cloud Platform project you want. You can check the current project using,
gcloud config list project gcloud config set project
create vm in console
create vm as workstation, to download and install k8s.
ssh to vm workstation
ssh to 1st vm to download and install k8s,
gcloud compute --project "k8s-miniguide" ssh --zone "us-east1-b" "k8s-vm1" robert_lu_wang@k8s-vm1:~$ curl -sS https://get.k8s.io | bash Downloading kubernetes release v1.9.0 from https://dl.k8s.io/v1.9.0/kubernetes.tar.gz to /home/robert_lu_wang/kubernetes.tar.gz Is this ok? [Y]/n % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 161 100 161 0 0 989 0 --:--:-- --:--:-- --:--:-- 993 100 2805k 100 2805k 0 0 12.8M 0 --:--:-- --:--:-- --:--:-- 12.8M Unpacking kubernetes release v1.9.0 Kubernetes release: v1.9.0 Server: linux/amd64 (to override, set KUBERNETES_SERVER_ARCH) Client: linux/amd64 (autodetected) Will download kubernetes-server-linux-amd64.tar.gz from https://dl.k8s.io/v1.9.0 Will download and extract kubernetes-client-linux-amd64.tar.gz from https://dl.k8s.io/v1.9.0 Is this ok? [Y]/n % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 161 100 161 0 0 989 0 --:--:-- --:--:-- --:--:-- 987 100 399M 100 399M 0 0 276M 0 0:00:01 0:00:01 --:--:-- 359M md5sum(kubernetes-server-linux-amd64.tar.gz)=68d1fb2704bbdcc1eff997a1e6462615 sha1sum(kubernetes-server-linux-amd64.tar.gz)=ebeba901e875e725e410ecea9bc6b0c726e08a92 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 161 100 161 0 0 977 0 --:--:-- --:--:-- --:--:-- 981 100 14.9M 100 14.9M 0 0 34.0M 0 --:--:-- --:--:-- --:--:-- 34.0M md5sum(kubernetes-client-linux-amd64.tar.gz)=33dd4f6fc02aa3e8e050a30290a74c7f sha1sum(kubernetes-client-linux-amd64.tar.gz)=c9c135d3c39c0e6948e6044e3c07dcd8ce9ebc15 Extracting /home/robert_lu_wang/kubernetes/client/kubernetes-client-linux-amd64.tar.gz into /home/robert_lu_wang/kubernetes/platforms/linux/amd64 Add '/home/robert_lu_wang/kubernetes/client/bin' to your PATH to use newly-installed binaries. add k8s bin to PATH, robert_lu_wang@k8s-vm1:~$ export PATH=/home/robert_lu_wang/kubernetes/client/bin:$PATH robert_lu_wang@k8s-vm1:~$ env|grep PATH PATH=/home/robert_lu_wang/kubernetes/client/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
install cluster
cd kubernetes cluster/kube-up.sh
this script automatically create 1 master vm, and 3 worker vm.
cluster info
robert_lu_wang@k8s-vm1:~/kubernetes$ kubectl cluster-info Kubernetes master is running at https://104.198.193.23 GLBCDefaultBackend is running at https://104.198.193.23/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy Heapster is running at https://104.198.193.23/api/v1/namespaces/kube-system/services/heapster/proxy KubeDNS is running at https://104.198.193.23/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy kubernetes-dashboard is running at https://104.198.193.23/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy Metrics-server is running at https://104.198.193.23/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy Grafana is running at https://104.198.193.23/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy InfluxDB is running at https://104.198.193.23/api/v1/namespaces/kube-system/services/monitoring-influxdb:http/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
kubectl
list services
robert_lu_wang@k8s-vm1:~/kubernetes$ kubectl get --all-namespaces services NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes ClusterIP 10.0.0.1443/TCP 6m kube-system default-http-backend NodePort 10.0.228.218 80:30372/TCP 6m kube-system heapster ClusterIP 10.0.245.12 80/TCP 6m kube-system kube-dns ClusterIP 10.0.0.10 53/UDP,53/TCP 5m kube-system kubernetes-dashboard ClusterIP 10.0.237.126 443/TCP 5m kube-system metrics-server ClusterIP 10.0.117.233 443/TCP 5m kube-system monitoring-grafana ClusterIP 10.0.106.230 80/TCP 6m kube-system monitoring-influxdb ClusterIP 10.0.12.243 8083/TCP,8086/TCP 6m
list pods
robert_lu_wang@k8s-vm1:~/kubernetes$ kubectl get --all-namespaces pods NAMESPACE NAME READY STATUS RESTARTS AGE kube-system etcd-server-events-kubernetes-master 1/1 Running 0 5m kube-system etcd-server-kubernetes-master 1/1 Running 0 5m kube-system event-exporter-v0.1.7-64464bff45-xhhvj 1/1 Running 0 6m kube-system fluentd-gcp-v2.0.10-dqthf 1/1 Running 0 6m kube-system fluentd-gcp-v2.0.10-lzqgc 1/1 Running 0 6m kube-system fluentd-gcp-v2.0.10-mrs7l 1/1 Running 0 6m kube-system fluentd-gcp-v2.0.10-rssmd 1/1 Running 0 6m kube-system heapster-v1.5.0-5ff89c9bdb-7q72h 4/4 Running 0 5m kube-system kube-addon-manager-kubernetes-master 1/1 Running 0 5m kube-system kube-apiserver-kubernetes-master 1/1 Running 0 6m kube-system kube-controller-manager-kubernetes-master 1/1 Running 0 6m kube-system kube-dns-6c857864fb-2wrm9 3/3 Running 0 5m kube-system kube-dns-6c857864fb-96r9v 3/3 Running 0 6m kube-system kube-dns-autoscaler-69c5cbdcdd-lx5pd 1/1 Running 0 6m kube-system kube-proxy-kubernetes-minion-group-m3ww 1/1 Running 0 6m kube-system kube-proxy-kubernetes-minion-group-wjbs 1/1 Running 0 6m kube-system kube-proxy-kubernetes-minion-group-zmnp 1/1 Running 0 6m kube-system kube-scheduler-kubernetes-master 1/1 Running 0 6m kube-system kubernetes-dashboard-57889f9586-d276b 1/1 Running 0 6m kube-system l7-default-backend-57856c5f55-dtpdc 1/1 Running 0 6m kube-system l7-lb-controller-v0.9.7-kubernetes-master 1/1 Running 0 5m kube-system metrics-server-v0.2.0-97c97dd68-zttdh 2/2 Running 0 5m kube-system monitoring-influxdb-grafana-v4-554f5d97-25fbp 2/2 Running 0 6m kube-system rescheduler-v0.3.1-kubernetes-master 1/1 Running 0 5m
stop cluster
cd kubernetes cluster/kube-down.sh
gke cluster
create a gke cluster with 3 nodes from console,
gke authentication credentials
After creating your cluster, need to get authentication credentials to interact with the cluster.
robert_lu_wang@k8s-miniguide:~$ gcloud container clusters get-credentials cluster-1 --zone us-central1-a --project k8s-miniguide Fetching cluster endpoint and auth data. kubeconfig entry generated for cluster-1.
gke hello-server
robert_lu_wang@k8s-miniguide:~$ kubectl run hello-server --image=gcr.io/google-samples/hello-app:1.0 --port 8080 deployment "hello-server" created robert_lu_wang@k8s-miniguide:~$ kubectl expose deployment hello-server --type="LoadBalancer" service "hello-server" exposed robert_lu_wang@k8s-miniguide:~$ kubectl get service hello-server NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-server LoadBalancer 10.11.254.1568080:32245/TCP 15s robert_lu_wang@k8s-miniguide:~$ kubectl get service hello-server NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-server LoadBalancer 10.11.254.156 35.225.246.155 8080:32245/TCP 48s
app running result
http://35.225.246.155:8080/ Hello, world! Version: 1.0.0 Hostname: hello-server-732511812-wp6qd
cluster clean-up
robert_lu_wang@k8s-miniguide:~$ kubectl delete service hello-server service "hello-server" deleted robert_lu_wang@k8s-miniguide:~$ gcloud container clusters delete cluster-1 --zone us-central1-a The following clusters will be deleted. - [cluster-1] in [us-central1-a] Do you want to continue (Y/n)? y Deleting cluster cluster-1...done. Deleted [https://container.googleapis.com/v1/projects/k8s-miniguide/zones/us-central1-a/clusters/cluster-1].