Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
En esta página, se explica cómo conectarse a una instancia de Memorystore para Memcached.
Puedes conectarte a instancias de Memcached desde instancias de VM de Compute Engine, clústeres de Google Kubernetes Engine, funciones de Cloud Run, el entorno flexible de App Engine y el entorno estándar de App Engine.
Conéctate a una instancia de Memcached desde una VM de Compute Engine
Para conectarse a una instancia de Memcached, una instancia de VM de Compute Engine debe estar ubicada dentro del mismo proyecto y región, y también debe estar conectada a la misma red o red de VPC que la instancia de Memcached.
Conéctate a una VM de Linux. Para conocer los pasos para conectarte a una VM de Linux, consulta la Guía de inicio rápido para usar una VM de Linux.
Si usaste una imagen basada en Debian para crear tu instancia de VM como se describe en la guía de inicio rápido, instala telnet mediante apt-get:
sudo apt-get install telnet
Desde la terminal, usa Telnet hasta la dirección IP de uno de los nodos de Memcached y reemplaza variables por los valores apropiados.
telnet node-ip-address 11211
Si funciona de forma correcta, deberías ver el siguiente resultado con [bracketed-variables] reemplazado por las variables de tu proyecto:
Trying [node-ip-address]
Connected to [node-ip-address]
En la sesión de telnet, ingresa algunos comandos de Memcached:
Ingresa:
get greeting
Resultado:
END
Ingrese:
set greeting 1 0 11
hello world
Resultado:
STORED
Ingrese:
get greeting
Resultado:
VALUE greeting 1 11
hello world
END
Memorystore para Memcached admite bibliotecas estándar de Memcached de código abierto.
Conéctate a una instancia de Memcached desde un clúster de Google Kubernetes Engine
Puedes conectarte a tus instancias de Memcached con clústeres de GKE que se encuentran en la misma región y están conectados a la misma red que tu instancia.
Ve a la página de Google Kubernetes Engine en la consola de Google Cloud.
Google Kubernetes Engine
Haz clic en el clúster GKE desde el que deseas conectarte. Si aún no tienes un clúster, crea uno en la misma zona y región que tu instancia de Memcached con los alias de IP habilitados. Para obtener instrucciones sobre cómo crear un clúster con alias de IP habilitados, consulta Crea un clúster nativo de la VPC.
Haz clic en el botón Conectar a la derecha del nombre de tu clúster y haz clic en el botón Ejecutar en Cloud Shell en la ventana que aparece.
Configura el acceso a la línea de comandos de kubectl mediante la ejecución del siguiente comando:
cluster-zone es la zona en la que se encuentra tu clúster. También debe ser la zona en la que se encuentra tu instancia de Memcached.
project-id es el proyecto en el que se encuentran tu clúster y tu instancia de Memcached.
Si el comando se ejecuta correctamente, deberías recibir el siguiente mensaje:
kubeconfig generated for cluster-name
Si no recibes este mensaje, asegúrate de haber ingresado la información correcta del clúster en el comando.
Si tu clúster es de la versión 1.8 o superior y tienes habilitados los alias de IP, omite este paso. Si tu clúster es de la versión 1.7 o inferior, o tu clúster de la versión 1.8 o superior no tiene habilitados los alias de IP, sigue estos pasos alternativos antes de intentar conectarte a tu instancia.
Solución alternativa
Ejecuta estos tres comandos y reemplaza reserved-ip-range por el rango de IP reservado de tu instancia:
Para obtener más información sobre los alias de IP, incluido cómo crear un clúster con esta configuración habilitada, consulta Crea un clúster nativo de la VPC.
Usa el siguiente comando para conectarte a un shell Bash:
kubectl run -i --tty busybox --image=busybox -- sh
Conecta Telnet a tu instancia de Memcached mediante una de las direcciones IP de tu nodo y el número de puerto de tu instancia:
telnet node-ip-address 11211
En la sesión de telnet, ingresa algunos comandos de Memcached:
Ingresa:
get greeting
Resultado:
END
Ingrese:
set greeting 1 0 11
hello world
Resultado:
STORED
Ingrese:
get greeting
Resultado:
VALUE greeting 1 11
hello world
END
Memorystore para Memcached admite bibliotecas estándar de Memcached de código abierto.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-05 (UTC)"],[],[],null,["# Connect to a Memcached instance\n\nThis page explains how to connect to a Memorystore for Memcached instance.\nYou can connect to Memcached instances from Compute Engine VM instances,\nGoogle Kubernetes Engine clusters, Cloud Run functions, the App Engine\nflexible environment, and the App Engine standard environment.\n\nBefore you can access Memorystore with Cloud Run functions, you\nneed follow the setup instructions at [Connecting to internal resources in a VPC network](/functions/docs/connecting-vpc#connecting_to_your_vpc_network).\n\nAlso, before you can access Memorystore with the App Engine\nstandard environment, you need to follow the setup instructions at [Connecting\nto internal resources in a VPC network](/appengine/docs/standard/python/connecting-vpc#creating_a_connector).\n| **Note:** You can use any open source Memcached client library to connect to Memorystore for Memcached.\n\nConnecting to a Memcached instance from a Compute Engine VM\n-----------------------------------------------------------\n\nIn order to connect to a Memcached instance, a Compute Engine VM instance must\nbe located within the same project and region, and must also be connected to the\nsame network or VPC network as the Memcached instance.\n\n1. Connect to a Linux VM. For steps to connect to a Linux VM, see [Quickstart Using a Linux VM](/compute/docs/create-linux-vm-instance).\n If you used a Debian based image to create your VM instance as described in the\n quickstart, install `telnet` using `apt-get`:\n\n ```\n sudo apt-get install telnet\n ```\n2. From the terminal, telnet to the IP address of one of the Memcached nodes,\n replacing \u003cvar translate=\"no\"\u003evariables\u003c/var\u003e with appropriate values.\n\n ```\n telnet node-ip-address 11211\n ```\n\n If it works correctly, you should see the following output with the\n `[bracketed-variables]` replaced by your project's variables: \n\n ```\n Trying [node-ip-address]\n Connected to [node-ip-address]\n ```\n3. In the telnet session, enter some Memcached commands:\n\n Enter: \n\n ```\n get greeting\n ```\n\n Result: \n\n ```\n END\n ```\n\n Enter: \n\n ```\n set greeting 1 0 11\n hello world\n ```\n\n Result: \n\n ```\n STORED\n ```\n\n Enter: \n\n ```\n get greeting\n ```\n\n Result: \n\n ```\n VALUE greeting 1 11\n hello world\n END\n ```\n\nMemorystore for Memcached supports standard open source Memcached libraries.\n\nConnecting to a Memcached instance from a Google Kubernetes Engine cluster\n--------------------------------------------------------------------------\n\n| **Note:** You cannot connect to a Memorystore for Memcached instance from a Google Kubernetes Engine cluster without VPC-native/IP aliasing enabled. To verify if your instance has VPC-native/IP aliasing enabled, check your cluster's details page in the Google Cloud console. Alternatively, run [`gcloud container clusters describe`](/sdk/gcloud/reference/container/clusters/describe) and verify if `useIpAliases: true` is present. \n|\n| It is easiest to enable VPC-native/IP aliasing during cluster creation. When creating your cluster, select **VPC Native** under advanced options. For more details, see [Creating VPC-native clusters using Alias IPs](/kubernetes-engine/docs/how-to/alias-ips).\n\nYou can connect to your Memcached instances using GKE\nclusters that are in the same region and connected to the same network as your\ninstance.\n\n1. Go to the Google Kubernetes Engine page in the Google Cloud console.\n\n [Google Kubernetes Engine](https://console.cloud.google.com/kubernetes/list?)\n\n2. Click on the GKE cluster you'd like to connect from. If\n you don't already have a cluster, create one in the same zone and region as\n your Memcached instance with IP aliases enabled. For instructions on how to\n create a cluster with IP aliases enabled, see the [Creating a VPC-native cluster](/kubernetes-engine/docs/how-to/alias-ips#creating_a_new_cluster_with_ip_aliases).\n\n3. Click the **Connect** button to the right of your cluster's name, then click\n the **Run in Cloud Shell** button in the window that appears.\n\n4. Configure `kubectl` command line access by running the following command:\n\n ```\n gcloud container clusters get-credentials cluster-name --zone=cluster-zone --project=project-id\n ```\n - \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003ecluster-name\u003c/code\u003e\u003c/var\u003e is the name of your cluster.\n\n - \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003ecluster-zone\u003c/code\u003e\u003c/var\u003e is the zone your cluster is in. This must also be\n the zone your Memcached instance is in.\n\n - \u003cvar translate=\"no\"\u003e\u003ccode translate=\"no\" dir=\"ltr\"\u003eproject-id\u003c/code\u003e\u003c/var\u003e is the project in which your cluster and your\n Memcached instance are located.\n\n If the command is successful, you should receive the following message: \n\n ```\n kubeconfig generated for cluster-name\n ```\n\n If you do not receive this message, make sure you entered the correct cluster\n information into the command.\n5. If your cluster is version 1.8 or higher **and** has IP aliases enabled, skip\n this step. If your cluster is version 1.7 or lower, or your version 1.8 or\n higher cluster doesn't have IP aliases enabled, follow these workaround steps\n before trying to connect to your instance:\n\n #### Workaround\n\n Run these three commands, replacing \u003cvar translate=\"no\"\u003ereserved-ip-range\u003c/var\u003e with the\n reserved IP range of your instance: \n\n ```\n git clone https://github.com/bowei/k8s-custom-iptables.git\n ``` \n\n ```\n cd k8s-custom-iptables/\n ``` \n\n ```\n TARGETS=\"reserved-ip-range\" ./install.sh\n ```\n Note: If you don't know the reserved IP range of your instance, you can find out by running the following command: \n\n ```\n gcloud memcache instances describe instance-id --region=region\n ```\n\n For more information about IP aliases, including how to create a cluster with this setting enabled, see [Creating a VPC-native cluster](/kubernetes-engine/docs/how-to/alias-ips#creating_a_new_cluster_with_ip_aliases).\n6. Use the following command to connect to a bash shell:\n\n ```\n kubectl run -i --tty busybox --image=busybox -- sh\n ```\n7. Telnet to your Memcached instance using one of your node's IP addresses and\n your instance's port number:\n\n ```\n telnet node-ip-address 11211\n ```\n8. In the telnet session, enter some Memcached commands:\n\n Enter: \n\n ```\n get greeting\n ```\n\n Result: \n\n ```\n END\n ```\n\n Enter: \n\n ```\n set greeting 1 0 11\n hello world\n ```\n\n Result: \n\n ```\n STORED\n ```\n\n Enter: \n\n ```\n get greeting\n ```\n\n Result: \n\n ```\n VALUE greeting 1 11\n hello world\n END\n ```\n\nMemorystore for Memcached supports standard open source Memcached libraries.\n\nWhat's next\n-----------\n\n- [Use the Auto Discovery service](/memorystore/docs/memcached/using-auto-discovery).\n- [Monitor your Memcached instances](/memorystore/docs/memcached/monitoring-instances)."]]