Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • Software and Tools
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Go Premium
  • DevOps Lifecycle
  • DevOps Roadmap
  • Docker Tutorial
  • Kubernetes Tutorials
  • Amazon Web Services [AWS] Tutorial
  • AZURE Tutorials
  • GCP Tutorials
  • Docker Cheat sheet
  • Kubernetes cheat sheet
  • AWS interview questions
  • Docker Interview Questions
  • Ansible Interview Questions
  • Jenkins Interview Questions
Open In App
Next Article:
What is DevOps ?
Next article icon

Kubernetes - Kubectl

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Kubectl is a command-line software tool that is used to run commands in command-line mode against the Kubernetes Cluster. Kubectl runs the commands in the command line, Behind the scenes it authenticates with the master node of Kubernetes Cluster with API calls and performs the operations on Kubernetes Resources such as Creation, Deletion, Modification, and Viewing Operations. Here the Resources include such as Pod, Service, Deployment, Secrets, ReplicationController, ReplicationSet, Persistent Volumes, etc.

What is kubectl?

Kubectl is command-line software that helps to run commands in the Kubernetes Cluster. It acts as a bridge between clients and the Kubernetes cluster providing communication through API requests using http or https protocols. It converts the commands entered in the command line from a user into API requests and pass to the API server of the Kubernetes master Node with proper Authentication. It helps to manage the containers and deploy apps and other resources to run smoothly.

Kubernetes Internals

In Kubernetes the Orchestration of containerized applications are powered through operations of master and worker nodes. The Internal Resources of Kubernetes brings the robustness in Orchestrating the containered applications. The Internals of Kubernetes includes k8s etcd resource for storing distributed key-value pair of configuration, K8s Controller Manager for maintaining desired state of containered applications, K8s Scheduler resource for distributed of workloads, k8s API Server resources for acting at front of the control plane in transmission of API calls.. These internals resources of the kubernetes provides the seamless features of ensuring scalability, resilience in container management.

To Know more about the kubernetes Internals refer this article - Kubernetes Cluster

Architecture of Kubectl in Kubernetes Cluster

The Kubectl is a client-side tool that acts as a bridge between the users and the K8s cluster. It provides an interactive command-line interface for the users to run the commands with kubectl against the Kubernetes cluster. The Architecture involves once the users/client executes a command through the command line it is authenticated with the master node of k8s Cluster through the Kubernetes API server. Based on the type of API request Kubernetes API server facilitates the orchestration and coordination of Kubernetes resources such as Control Manager, Kubernetes Scheduler, and Etcd resources.. within the Kubernetes Cluster. The following Diagram illustrates the above-discussed architecture workflow of kubectl in Kubernetes.

Kubernetes-Kubectl workflow

Installation of  Kubectl

You can setup the installation of Kubectl on any of the following sources of environment.

  • Linux
  • macOS
  • Windows

Once you install Kubectl on kuba respective environment you can cross-check by running the below command.

$ kubectl version 

In the following screenshot you versioning details of kubectl:

kubectl-version

To know more about of kubectl, please read this cheatsheet: kubectl cheatsheet

Syntax

$ kubectl [command]  [TYPE]  [NAME]  [flags]

  • Command: This will include the operation mentioned below you want to perform regarding the specific resource.
    • Create
    • get
    • describe
    • delete
  • Type: Here you have to mention the specific resource provided by Kubernetes that you want to create like kubernetes pods, Kubernetes namespaces, Kubernetes secrets, Kubernetes deployment, replica sets, and many more. This option is a case-sensitive.
  • NAME: Here we will provide the name which is case-sensitive.
  • flags: This will use to pass the flags like address or port number.

How to run the commands for resources that kubectl provides.

Create a Resource Using Kubectl

In Kubernetes, a resource gets created inside a namespace which resource using which we can create other resources in a separate environment.

First, we are creating a namespace inside which we will create our Pod.

$ kubectl create namespace geeksforgeeks

We can create a Pod using the below YAML file.

apiVersion: v1
kind: Pod
metadata:
name: geeksforgeeks
namespace: geeksforgeeks
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

The above file is a configuration file using which we are creating a pod of name geeksforgeeks in namespace geeksforgeeksnamespace which is an Nginx server. Similarly, we can create other resources like secrets, replica sets, etc by just changing the name in front of the kind and mentioning the key value in metadata and spec accordingly.

$ kubectl create -f geeksforgeekspod.yaml

The above discussed commands are implemented in the screenshot, try on implementing this

pod_creation2

To Get the Resources

Command to see all the namespaces.

kubectl get namespaces

To see the namespace geeksforgeeksnamespace run the below command.

$ kubectl get namespaces

Command to see the list of all pods.

$ kubectl get pods

This will show the pods in the default namespace. To list all the pods in a particular namespace we can pass the flag -n and the name of the namespace with `kubectl get pods` command.

$ kubectl get pods -n <namespace_name>

So if we have to list down the pod that we have created in namespace geeksforgeeksnamespace, run the below command.

$ kubectl get pod -n geeksforgeeks

Describe a Resource

To describe the resource we have to run kubectl describe command and then mention the resource and the namespace that resource is in.

$ kubectl describe resource_name -n namespace_name

So now we will describe our pod.

$ kubectl describe pod geeksforgeeks -n geeksforgeeks
Name:         geeksforgeeks
Namespace: geeksforgeeksnamespace
Priority: 0
Node: cluc-control-plane/172.19.0.8
Start Time: Sun, 15 May 2022 11:17:36 +0000
Labels: <none>
Annotations: cni.projectcalico.org/containerID: ce6d80d1a912
a3edda623aeab52c2995aee87e7c225d6258f888d70a36c79b68
cni.projectcalico.org/podIP: 10.244.206.106/32
cni.projectcalico.org/podIPs: 10.244.206.106/32
Status: Running
IP: 10.244.206.106
IPs:
IP: 10.244.206.106
Containers:
nginx:
Container ID: containerd://b265bb64e9cea231b9e52a150f2
1399b4d051000c2c5dc9bc03cf1de42d060ae
Image: nginx:1.14.2
Image ID: docker.io/library/nginx@sha256:f7988fb6c02e0
ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 15 May 2022 11:19:20 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount
from kube-api-access-gz2zs (ro)
Conditions:
Type Status
Initialized True 
Ready True 
ContainersReady True 
PodScheduled True 
Volumes:
kube-api-access-gz2zs:
Type: Projected (a volume that contains
injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events: <none>

Creating namespace with name "geeksforgeeks" and creating pod with name "geeksforgeeks" inside this namespace is showed in this screenshot:

Creating pod in namespaces

Delete the Resources

kubectl delete command is used to delete the resources by passing their name and namespace if we are deleting other resources other than a namespace.

$ kubectl delete resource
resource_name -n namespace_name

Now we will delete the pod and namespace.

$ kubectl delete pod geeksforgeeks -n geeksforgeeks

You can verify whether the pod is deleted or not by running kubectl get pod -n geeksforgeeksnamespace.

Now we will delete the namespace instead of -n option as follows.

$ kubectl delete namespace geeksforgeeks

Note: If we delete the namespace before the pod then the pod will delete automatically with other resources in that namespace.

The following screenshot shows the practical deleting pods in namespaces and deleting namespaces:

Deleting pods and namespaces

Popular Commands Usage Of Kubectl

There are many commands in kubectl and their popularity depends on the requirements and its specific Use case. However, here some of the commands list that are some commonly used and popular kubectl commands:

  • The following command helps in listing all the pods in the specified namespace.
  kubectl get pods -n namespace1
  • The following command is used to describe a Deployment resource in Kubernetes.
  kubectl describe deployment <deployment-name>
  • The following command is used to scale/adjust the replicas for a deployment up or down.
  kubectl scale deployment <deployment-name> --replicas=<number>
  • The following command is used to create a Kubernetes service and to expose the pods to the cluster through a YAML file.
  kubectl apply -f <service-definition.yaml>
  • The following command is used for deleting a specific resource in a Kubernetes such as a pod, or deployment.
  kubectl delete pod mypod

The above specific commands you can use depend on the tasks you are going to perform within your Kubernetes cluster. Additionally it is always a recommended idea to refer the official documentation of Kubernetes for detailed information on kubectl commands and their usage.

How To Run Kubernetes Yaml Code Files With Kubectl ?

By defining the desired resources with Yaml syntax, you can create and run a Kubernetes YAML file using the 'kubectl' command for configuring those appliances to the Kubernetes cluster. Here is the step-by-step process of guidelines to create and run the k8s file with kubectl:

Create a Yaml File

On using a text editor create a YAML file describing the specification of resources that to create or modify. For Example a 'Deployment.yaml' file is created as a sample.

apiVersion: apps/v1
kind: Deployment
metadata:
name: mydeployment
spec:
replicas: 4
selector:
matchLabels:
app: myapp1
template:
metadata:
labels:
app: myapp1
spec:
containers:
- name: mycontainer1
image: nginx:latest

The following screenshot shows the creation of deployment practically with name "deployment" with replicas - 4

Creation of deployment

Applying The Configuration

Use the Deployment.yaml file with the 'kubectl apply' command to apply the configurations to the Kubernetes cluster. here I am using default namespace, to specify the use -n namespace_name at the end of the command.

kubectl create -f  Deployment.yaml

When your are applying the configuration for the first time with the specified yaml file we use create option. i.e., kubectl create -f <file_name>. While the option `kubectl apply` can be used for the both creation and updating the configuration of the file ie., kubectl apply -f <file_name>

The following screenshot shows the practical on updating the deployment configuration file with changing its replicas from 4 to 2.

Updating the deployment configuration

To Check The Status Of The Resources in K8s

  • To verify whether the applied configurations of the resources from the file is created or updated successfully or not. Try on running the kubectl get command with the resource name i.e., kubectl get <resource_name>
 kubectl get deployments
kubectl get pods

Describing the Resources ( Optional )

  • For knowing the detailed information about a specific resource, try on specifying resource type and resource type name with kubectl command.
 kubectl describe deployment mydeployment

Updating The Resources ( Optional )

To make changes any changes to your resources, you can update the YAML file, and then reapply the configuration using kubectl apply command with <filename>.

 kubectl apply -f Deployment.yaml

Deleting The Resources (Optional)

To delete a specific resource that you created try on running the `kubectl delete` command with resource type and resource type name.

 kubectl delete -f Deployment.yaml

Features of Kubernetes Kubectl Tool

  • Management of Resources: Kubectl provides efficient management of Kubernetes resources such as pods, deployments, and Kubernetes services in the cluster with seamless interaction over performing operations such as creating, delete, modifying, and list of the resources.
  • Cluster Inspection and Debugging: It is helpful in offering effective commands to inspect and debug the cluster resources. Users can fetch detailed information regarding the resources such as pods, nodes, and configurations for troubleshooting and performance analysis.
  • Context Switching and Multi-Cluster Management: kubectl allows users to support context switching and seamless management of the Kubernetes cluster. It provides effective commands for both switching context and management of k8s cluster with namespaces.
  • Plugin Extensibility: kubectl allows the users the extend its functionality through Krew plugin manager for automation of tasks providing new effective commands to enhance overall user experience.

What are the popular plugins of Kubectl?

Kubectl plugins help extend the capabilities of the 'Kubectl' command. It allows the automation of tasks and introduces specialized commands to increase productivity offering shortcuts and customized options. The following are a few widely used popular kubectl plugins:

  • Krew ( Plugin Manager ):Krew is helpful for users to easily install and update the plugins by simplified management of plugins. It provides a centralized repository by supporting a wide range of plugins to improve the overall experience.
  • kube-ps1 ( Shell Prompt Integration):It offers real-time visibility of current clusters and namespaces through integrating Kubernetes context into the shell prompt. It comes as a lightweight plugin that reduces manual context checks and improves the productivity of the command line.
  • kubectx and kubens (Context Switching ): These plugins are effective in management of k8s resources. 'kubectx' helps in effortless switch between the clusters whereas 'kubens' helps in simplify the namespace changes. It helps in efficient management of context, reducing the errors in multi-cluster and multi-namespaces.

What Are The Alternatives Tools To The Kubectl?

For Interacting with Kubernetes clusters in command-line mode, kubectl is the primary and widely used command-line tool offering different features and user experience. Here are some other notable alternative command line tools for Kubectl:

  • OC ( Openshift Command-Line Tool ): The Openshift Command line tool is effective for managing the clusters extending beyond the `Kubectl` functionalities. It provides specific additional features for Openshift environments with commands such as projects, routes and build configurations. It helps in providing a seamless experience for the developers and administrators.
  • K9s ( Kubernetes Terminal UI ):Kubernetes Terminal UI is a specific Kubernetes tool offering an interactive and visually-performing terminal UI. It provides a dynamic interface, real-time updates, and efficient navigation. It is a recommended tool for users who prefer the graphical representation of their clusters along with strong command line performance.
  • Helm ( Kubernetes Package Manager ): Helm comes up with a package manager approach for simplifying the application management of Kubernetes. It packages the k8s manifest files into the shareable charts for easy installations, upgrades, and uninstall of applications providing a high level of abstraction compared to Yaml files.

Conclusion

Kubectl stands as a powerfully effective tool for Kubernetes administrators and developers in management and operations over the clusters in multiple environments. It helps with the effortless management of resources, troubleshooting issues, and navigating in complex clusters. kubectl facilitates context-context switching capabilities and extends the functionality with plugins support providing a seamless interaction with containerized applications.


Next Article
What is DevOps ?

A

aman55
Improve
Article Tags :
  • DevOps

Similar Reads

    DevOps Tutorial
    DevOps is a combination of two words: "Development" and "Operations." It’s a modern approach where software developers and software operations teams work together throughout the entire software life cycle, from planning and coding to testing, deploying, and monitoring.The main idea of DevOps is to i
    9 min read

    Introduction

    What is DevOps ?
    DevOps is a modern way of working in software development in which the development team (who writes the code and builds the software) and the operations team (which sets up, runs, and manages the software) work together as a single team.Before DevOps, the development and operations teams worked sepa
    10 min read
    DevOps Lifecycle
    The DevOps lifecycle is a structured approach that integrates development (Dev) and operations (Ops) teams to streamline software delivery. It focuses on collaboration, automation, and continuous feedback across key phases planning, coding, building, testing, releasing, deploying, operating, and mon
    10 min read
    The Evolution of DevOps - 3 Major Trends for Future
    DevOps is a software engineering culture and practice that aims to unify software development and operations. It is an approach to software development that emphasizes collaboration, communication, and integration between software developers and IT operations. DevOps has come a long way since its in
    7 min read

    Version Control

    Version Control Systems
    A Version Control System (VCS) is a tool used in software development and collaborative projects to track and manage changes to source code, documents, and other files. Whether you are working alone or in a team, version control helps ensure your work is safe, organized, and easy to collaborate on.
    5 min read
    Merge Strategies in Git
    In Git, merging is the process of taking the changes from one branch and combining them into another. The merge command in Git will compare the two branches and merge them if there are no conflicts. If conflicts arise, Git will ask the user to resolve them before completing the merge.Merge keeps all
    4 min read
    Which Version Control System Should I Choose?
    While building a project, you need a system wherein you can track the modifications made. That's where Version Control System comes into the picture. It came into existence in 1972 at Bell Labs. The very first VCS made was SCCS (Source Code Control System) and was available only for UNIX. When any p
    5 min read

    Continuous Integration (CI) & Continuous Deployment (CD)

    What is CI/CD?
    CI/CD is the practice of automating the integration of code changes from multiple developers into a single codebase. It is a software development practice where the developers commit their work frequently to the central code repository (Github or Stash). Then there are automated tools that build the
    10 min read
    Understanding Deployment Automation
    In this article we will discuss deployment automation, categories in Automated Deployment, how automation can be implemented in deployment, how it is assisting DevOps and finally the benefits and drawbacks of Deployment Automation. So, let's start exploring the topic in detail. Deployment Automation
    4 min read

    Containerization

    What is Docker?
    Have you ever wondered about the reason for creating Docker Containers in the market? Before Docker, there was a big issue faced by most developers whenever they created any code that code was working on that developer computer, but when they try to run that particular code on the server, that code
    12 min read
    What is Dockerfile Syntax?
    Pre-requsites: Docker,DockerfileA Dockerfile is a script that uses the Docker platform to generate containers automatically. It is essentially a text document that contains all the instructions that a user may use to create an image from the command line. The Docker platform is a Linux-based platfor
    5 min read
    Kubernetes - Introduction to Container Orchestration
    In this article, we will look into Container Orchestration in Kubernetes. But first, let's explore the trends that gave rise to containers, the need for container orchestration, and how that it has created the space for Kubernetes to rise to dominance and growth. The growth of technology into every
    4 min read

    Orchestration

    Kubernetes - Introduction to Container Orchestration
    In this article, we will look into Container Orchestration in Kubernetes. But first, let's explore the trends that gave rise to containers, the need for container orchestration, and how that it has created the space for Kubernetes to rise to dominance and growth. The growth of technology into every
    4 min read
    Fundamental Kubernetes Components and their role in Container Orchestration
    Kubernetes or K8s is an open-sourced container orchestration technology that is used for automating the manual processes of deploying, managing and scaling applications by the help of containers. Kubernetes was originally developed by engineers at Google and In 2015, it was donated to CNCF (Cloud Na
    12 min read
    How to Use AWS ECS to Deploy and Manage Containerized Applications?
    Containers can be deployed for applications on the AWS cloud platform. AWS has a special application for managing containerized applications. Elastic Container Service (ECS) serves this purpose. ECS is AWS's container orchestration tool which simplifies the management of containers. All the containe
    4 min read

    Infrastructure as Code (IaC)

    What is Infrastructure as Code (IaC)?
    Infrastructure as Code (IaC) is a method of managing and provisioning IT infrastructure using code rather than manual configuration. It allows teams to automate the setup and management of their infrastructure, making it more efficient and consistent. This is particularly useful in the DevOps enviro
    7 min read
    Introduction to Terraform
    Many people wonder why we use Terraform when there are already so many Infrastructure as Code (IaC) tools out there. So, before learning Terraform, let’s understand why it was created.Terraform was made to solve some common problems with existing IaC tools. Some tools, like AWS CloudFormation, only
    15 min read
    What is AWS Cloudformation?
    Amazon Web Services(AWS) offers cloud formation as a service by which you can provision and manage complicated services offered by AWS by using the code. CloudFormation will help you to manage the infrastructure and the services in the form of a declarative way. Table of ContentIntroduction to AWS C
    14 min read

    Monitoring and Logging

    Working with Prometheus and Grafana Using Helm
    Pre-requisite: HELM Package Manager Helm is a package manager for Kubernetes that allows you to install, upgrade, and manage applications on your Kubernetes cluster. With Helm, you can define, install, and upgrade your application using a single configuration file, called a Chart. Charts are easy to
    5 min read
    Working with Monitoring and Logging Services
    Pre-requisite: Google Cloud Platform Monitoring and Logging services are essential tools for any organization that wants to ensure the reliability, performance, and security of its systems. These services allow organizations to collect and analyze data about the health and behavior of their systems,
    5 min read
    Microsoft Teams vs Slack
    Both Microsoft Teams and Slack are the communication channels used by organizations to communicate with their employees. Microsoft Teams was developed in 2017 whereas Slack was created in 2013. Microsoft Teams is mainly used in large organizations and is integrated with Office 365 enhancing the feat
    4 min read

    Security in DevOps

    What is DevSecOps: Overview and Tools
    DevSecOps methodology is an extension of the DevOps model that helps development teams to integrate security objectives very early into the lifecycle of the software development process, giving developers the team confidence to carry out several security tasks independently to protect code from adva
    10 min read
    DevOps Best Practices for Kubernetes
    DevOps is the hot topic in the market these days. DevOps is a vague term used for wide number of operations, most agreeable defination of DevOps would be that DevOps is an intersection of development and operations. Certain practices need to be followed during the application release process in DevO
    11 min read
`; $(commentSectionTemplate).insertBefore(".article--recommended"); } loadComments(); }); }); function loadComments() { if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • DSA Tutorial
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences