HOWTO
- https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
- https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl
Install kubectl using RPM
dave@dave:~$ cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
EOF
[sudo] password for dave:
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
dave@dave:~$ sudo yum install -y kubectl
Fedora 39 - x86_64 - Updates 118 kB/s | 16 kB 00:00
Fedora 39 - x86_64 - Updates 1.8 MB/s | 2.7 MB 00:01
Kubernetes 12 kB/s | 5.7 kB 00:00
Dependencies resolved.
==============================================================================================================================================================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================================================================================================================================================
Installing:
kubectl x86_64 1.29.0-150500.1.1 kubernetes 10 M
Transaction Summary
==============================================================================================================================================================================================================================================================================================================================
Install 1 Package
Total download size: 10 M
Installed size: 47 M
Downloading Packages:
kubectl-1.29.0-150500.1.1.x86_64.rpm 12 MB/s | 10 MB 00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 12 MB/s | 10 MB 00:00
Kubernetes 7.9 kB/s | 1.7 kB 00:00
Importing GPG key 0x9A296436:
Userid : "isv:kubernetes OBS Project <isv:kubernetes@build.opensuse.org>"
Fingerprint: DE15 B144 86CD 377B 9E87 6E1A 2346 54DA 9A29 6436
From : https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : kubectl-1.29.0-150500.1.1.x86_64 1/1
Verifying : kubectl-1.29.0-150500.1.1.x86_64 1/1
Installed:
kubectl-1.29.0-150500.1.1.x86_64
Complete!
dave@dave:~$
Check k8s cluster via gcloud
$ gcloud container clusters list
NAME LOCATION MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
dave-cluster europe-west10 1.27.3-gke.100 1.1.1.1 e2-small 1.27.3-gke.100 1 RUNNING
sudo yum install google-cloud-sdk-gke-gcloud-auth-plugin
[sudo] password for dave:
Last metadata expiration check: 0:29:49 ago on Thu 14 Dec 2023 10:05:11 AM CET.
Dependencies resolved.
==================================================================================================================================================================================================================
Package Architecture Version Repository Size
==================================================================================================================================================================================================================
Installing:
google-cloud-sdk-gke-gcloud-auth-plugin x86_64 457.0.0-1 google-cloud-sdk 3.6 M
Transaction Summary
==================================================================================================================================================================================================================
Install 1 Package
Total download size: 3.6 M
Installed size: 12 M
Is this ok [y/N]: y
Downloading Packages:
4b31246c89a3b0d6ec3d0120181b2e556f2a4f483a412c1f89bca3d475061438-google-cloud-sdk-gke-gcloud-auth-plugin-457.0.0-1.x86_64.rpm 9.9 MB/s | 3.6 MB 00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 9.8 MB/s | 3.6 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : google-cloud-sdk-gke-gcloud-auth-plugin-457.0.0-1.x86_64 1/1
Running scriptlet: google-cloud-sdk-gke-gcloud-auth-plugin-457.0.0-1.x86_64 1/1
Verifying : google-cloud-sdk-gke-gcloud-auth-plugin-457.0.0-1.x86_64 1/1
Installed:
google-cloud-sdk-gke-gcloud-auth-plugin-457.0.0-1.x86_64
Complete!
Check the version
dave@dave:~$ gke-gcloud-auth-plugin --version
Kubernetes v1.28.2-alpha+dafa3f6c671d0a0d879f3b203588c782ecb87a18
Update the kubectl configuration to use the plugin:
$ gcloud container clusters get-credentials dave-cluster \
--zone=europe-west10
Fetching cluster endpoint and auth data.
kubeconfig entry generated for dave-cluster.
dave@dave:~$ kubectl get namespaces
NAME STATUS AGE
default Active 13m
gke-gmp-system Active 12m
gke-managed-filestorecsi Active 13m
gmp-public Active 12m
kube-node-lease Active 13m
kube-public Active 13m
kube-system Active 13m
Interact with k8s cluster via kubectl
dave@dave:~$ kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://34.32.43.197
name: gke_dave-terraform_europe-west10_dave-cluster
contexts:
- context:
cluster: gke_dave-terraform_europe-west10_dave-cluster
user: gke_dave-terraform_europe-west10_dave-cluster
name: gke_dave-terraform_europe-west10_dave-cluster
current-context: gke_dave-terraform_europe-west10_dave-cluster
kind: Config
preferences: {}
users:
- name: gke_dave-terraform_europe-west10_dave-cluster
user:
exec:
apiVersion: client.authentication.k8s.io/v1beta1
args: null
command: gke-gcloud-auth-plugin
env: null
installHint: Install gke-gcloud-auth-plugin for use with kubectl by following
https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
interactiveMode: IfAvailable
provideClusterInfo: true
Current context
dave@dave:~$ kubectl config current-context
gke_dave-terraform_europe-west10_dave-cluster
Store cluster info
$ gcloud container clusters get-credentials dave-cluster \
--zone=europe-west10
Fetching cluster endpoint and auth data.
kubeconfig entry generated for dave-cluster.
Google HOWTO for GKE k8s cluster creation
Create GKE cluster in GCP
Enable Google Kubernetes Engine in a Cloud project
For access to Google Kubernetes Engine, select or create a Cloud project to work in, then enable the required APIs:
- to ensure that you have the permissions you need, or select an existing project in which you have the
relevant permissions. - The necessary APIs are enabled:
- Kubernetes Engine API
- Artifact Registry API
Create a GKE cluster
Click the Navigation menu
icon, then Kubernetes Engine. You can see where it is by clicking the following button:
Click
.Clusters Click
.Create Choose Standard mode and click
.Configure In the
field, enter the nameName hello-cluster
.Under Location type, select
and then select a Compute Engine zone from theZonal drop-down list, such asZone us-west1-a
.Click
. This creates a GKE cluster. After the cluster is ready, a green checkmark appears next to the cluster name.Create
Deploy the sample app to GKE
Click
.Workloads Click
.Deploy In the Edit container section, select
.Existing container image In the Image path field, click
.Select In the
pane, select theSelect container image hello-app
image you pushed to Artifact Registry.Click
.Select Click
.Done Click
.Continue In the Configuration section, under Labels, enter
app
for Key
andhello-app
for Value.Under the Configuration section, click the
button under Configuration YAML. This opens a YAML configuration file representing the two Kubernetes API resources about to be deployed into your cluster.View YAML Click
.Close Click
.Deploy When the Deployment Pods are ready, the Deployment details page opens.
Under
, note the three running Pods for theManaged pods hello-app
Deployment.
Expose a sample app to the internet
Click
.Workloads Click on hello-app in the
column.Name From the Deployment details page, click the
button.Actions > Expose In the Expose dialog, under the
section, setPort Mapping toTarget port 8080
. drop-down list to Load balancer.Service type
Click
to create a Kubernetes Service forExpose hello-app
.When the Load Balancer is ready, the Service details page opens.
Scroll down to the Exposing services secion and copy the external IP from the
column for the newly exposed Load balancer .Endpoints - Note that Endpoints are used as External IP addresses for the next sections.
Click Next to learn how to deploy a new version of your app.
🎉 Success
You have successfully deployed a containerized web application!
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, delete your project if you're not going to use it again. If you intend to use it again, you can delete the individual resources.
Delete the project
To delete the Cloud project:
Delete individual resources
Delete the Service: This deallocates the Cloud Load Balancer created for your Service:
Delete the cluster: This deletes the resources that make up the cluster. Replace COMPUTE_ZONE in the command below with your own zone:
Delete your container images: This deletes the Docker images you pushed to Artifact Registry. Replace PROJECT-ID with your own:
Do more with Google Kubernetes Engine
Learn about Pricing for GKE .Use the Pricing Calculator to estimate costs .Read the Load Balancers tutorial, which demonstrates advanced load balancing configurations for web applications .Configure a static IP and domain name for your application .Explore other Kubernetes Engine tutorials .Try out other Google Cloud features for yourself. Have a look at our tutorials .
No comments:
Post a Comment