Showing posts with label curl. Show all posts
Showing posts with label curl. Show all posts

Thursday, April 22, 2021

Tip: curl: (23) Failed writing body

Symptom: 

When we run 

curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64

We get error

curl: (23) Failed writing body (0 != 1369)

Reason:

 Tt is due to  "/usr/local/bin/argocd"  is on the /usr/local/bin  directory which is owned by root user while we use normal user to run curl.

To fix it , change "/usr/local/bin/argocd" to be "/tmp/argocd"


Tuesday, April 14, 2020

Tip: use curl to test network port and DNS service in the Pod

curl is installed in most of docker images by default. Most of pods have it
We can use curl to test if network ports are open and DNS service is working

Example:  To test DB service port 1521
curl -v telnet://mydb.testdb.com:1521

*   Trying 1.1.1.1:1521...
*   TCP_NODELAY set
*   connect to 1.1.1.1:1521 port 1521 failed: Connection timed out
*   Failed to connect to port 1521: Connection timed out
*  Closing connection 0curl: (7) Failed to connect to  Connection timed out


It tells us DNS is working as we see the IP address 1.1.1.1
But port is not open.

To test url behind proxy, we can use blow command

curl -x http://proxy-mine:3128 -v telnet://abc.com:443

Monday, February 11, 2019

How To Add OKE Worker Nodes via OCI API

Requirement

  We have Kubernetes cluster running in OKE (Oracle Kubernetes Engine).  We would like to dig deeper to use OCI API to manager the node pool of our K8S cluster. ie we can add a new worker node into our new private subnet. With OCI API, we can have more flexibility to handle worker nodes in the cluster.  In this example, we plan to use curl and raw REST API calls to do that.  Later oci-cli or SDK would support such functions

Solution

  • First to install oci-curl .  It is a Bash Shell script. Please refer OCI Doc
  • Configure the oci-curl to use correct tenancyId , authUserId , keyFingerprint, privateKeyPath. More details Please refer OCI Credential Doc and  OCI API  details
  • Test oci-curl . If you can get result like below , it means it works 
# .   ./oci-curl.sh
# oci-curl containerengine.us-ashburn-1.oraclecloud.com GET "/20180222/clusterOptions/all"
{
  "kubernetesVersions": [
    "v1.10.11",
    "v1.11.5"
  ]
  • Prepare oke-nodepool.json The example of json file is like
{
  "compartmentId": "INSERT_YOUR_COMPARTMENT_ID",
  "clusterId": "INSERT_YOUR_CLUSTER_ID",
  "name": "INSERT_YOUR_NODE_POOL_NAME",
  "kubernetesVersion": "INSERT_YOUR_K8S_VERSION",
  "nodeImageName": "INSERT_YOUR_CUSTOM_IMAGE_OCID",
  "nodeShape": "INSERT_YOUR_SHAPE_NAME",
  "nodeMetadata": {
    "INSERT_YOUR_CUSTOM_KEY_1": "INSERT_YOUR_CUSTOM_VALUE_1",
    "INSERT_YOUR_CUSTOM_KEY_2": "INSERT_YOUR_CUSTOM_VALUE_2"
  },
  "initialNodeLabels": [
    {
      "key": "node.info/INSERT_YOUR_SAMPLE_KEY",
      "value": "INSERT_YOUR_SAMPLE_VALUE"
    }
  ],
  "sshPublicKey": "INSERT_YOUR_SSH_PUBLIC_KEY",
  "quantityPerSubnet": INSERT_YOUR_QTY_PER_SUBNET,
  "subnetIds": [
    "",
    "",
    ""
  ]
}
  • Create a node pool 
oci-curl containerengine.us-ashburn-1.oraclecloud.com POST ./oke-nodepool.json "/20180222/nodePools"
  • Go to the OCI ashburn console , a new nodepool would be created in OKE according to json file.

Thursday, January 17, 2019

Tip To Upload Files Into OCI Object Storage with Pre-Authenticated Requests

Symptom:

 Sometimes we need to provide many files to customers and customers need to provide files to us.
We can use OCI Object Storage Pre-Authenticated Requests to share data. Please refer more details on  Oracle Blog
    However after I create bucket Pre-Authenticated Requests , copy and paste url into our browser, we get below error

{"code":"NotFound","message":"Not Found"}

Solution:

The object Pre-Authenticated Requests can be writing or reading or both. 
The bucket Pre-Authenticated Requests is for writing purpose only (not reading)
So we need to use curl or other tools to put objects into the bucket. ie

curl https://objectstorage.us-ashburn-1.oraclecloud.com/p/THVqAQC1oIiwmerj6aK1lY5q3xG-rK3iGZvM2b1kq0/n/testtest/b/testdata/o/ --upload-file  mydata.tar