In here, we'll show you how to setup a kubernetes cluster in GCP.
In order to create a kubernetes cluster, follow the below steps:
-
Create a New project in you dashboard.
-
Choose
Kubernetes Engine
fromCompute
section in the gcp dashboard. -
In order to create a new cluster, push
Create cluster
botton. You can choose the version of kubernetes which you want to use and Zone of your cluster. -
You can choose the number of workers in
NODE POOLS
section: selectdefault-pool
-
Select the
Nodes
section fromdefault-pool
. (If you want to customize the specifications (e.g.RAM
andvCPU
) of nodes do this)
-
Push
Create
button and wait for creating cluster. After a few minutes you can see something like this -
You can see the details of your cluster by clicking the name of your cluster.
Your Kubernetes Cluster is ready now.
We want to connect to the cluster from our computer, so we need to configure gcloud SDK
in our system.
Now it needs to configure the kubectl
to access to our cluster. We can get the credentials of our cluster by pushing the Connect
botton in dashboard
copy the command-line access and run it into you terminal to create the config file of your cluster in ~/.kube/config
path.
ّImportant step: We need to open to access to port of utilization-server from outside the cluster:
UTILIZATION_PORT=30000
gcloud compute firewall-rules create utilization-server-node-port --allow tcp:${UTILIZATION_PORT}
In order to see you nodes, run the following command in your system:
kubectl get nodes
we want to run a pod in a specific node, so write the following content into file with name nginx_node_1.yaml
:
apiVersion: v1
kind: Pod
metadata:
name: nginx-1
labels:
web: nginx
spec:
containers:
- name: nginx-1
image: nginx
imagePullPolicy: IfNotPresent
nodeName: gke-kubernetes-cosolidat-default-pool-1041ab9e-cdt1
Run the command below to start a pod:
kubectl apply -f ./nginx_node_1.yaml