Giter Site home page Giter Site logo

k8s-api-tutorial's Introduction

Kubernetes API Walkthrough

Simple walkthrough of Kubernetes API

You can also execute the shell script to perform these steps.

Install JQ before trying the commands. Make sure that you have access to a Kubernetes cluster.

Verify Kubernetes setup

kubectl cluster-info
kubectl component-status

Configure the proxy

kubectl proxy --port=8000&

Open the Swagger UI in the browser

open http://localhost:8000/swagger-ui/

Invoke simple Kubernetes API

curl http://localhost:8000/api

cURL command equivalent to 'kubectl get nodes'

curl -s http://localhost:8000/api/v1/nodes | jq '.items[] .metadata.labels'

Create a Nginx Pod definition

cat > nginx-pod.json <<EOF
{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata":{
        "name": "nginx",
        "namespace": "default",
        "labels": {
            "name": "nginx"
        }
    },
    "spec": {
        "containers": [{
            "name": "nginx",
            "image": "nginx",
            "ports": [{"containerPort": 80}],
            "resources": {
                "limits": {
                    "memory": "128Mi",
                    "cpu": "500m"
                }
            }
        }]
    }
}
EOF

Create a Service definition to expose Nginx Pod

cat > nginx-service.json <<EOF
{
    "kind": "Service",
    "apiVersion": "v1",
    "metadata": {
        "name": "nginx-service",
        "namespace": "default",
        "labels": {"name": "nginx"}
    },
    "spec": {
        "ports": [{"port": 80}],
        "selector": {"name": "nginx"}
    }
}
EOF

Create the Pod object

curl -s http://localhost:8000/api/v1/namespaces/default/pods \
-XPOST -H 'Content-Type: application/json' \
[email protected] \
| jq '.status'

Create the Service object

curl -s http://localhost:8000/api/v1/namespaces/default/services \
-XPOST -H 'Content-Type: application/json' \
[email protected] \
| jq '.spec.clusterIP'

Verify the Pod with 'kubectl get pods'

kubectl get pods

Verify the Service with 'kubectl get svc'

kubectl get svc

Access Nginx default page through the proxy

curl http://localhost:8000/v1/proxy/namespaces/default/services/nginx-service/

Delete the Pod

curl http://localhost:8000/api/v1/namespaces/default/services/nginx-service -XDELETE

Delete the Service

curl http://localhost:8000/api/v1/namespaces/default/pods/nginx -XDELETE

k8s-api-tutorial's People

Contributors

janakiramm avatar

Watchers

James Cloos avatar Malhar Vora avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.