Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/jkyau-dsc/timeline

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/jkyau-dsc/timeline

  • v0.0.0-20200302215645-7afb8d5746c7
  • Source
  • Go
  • Socket score

Version published
Created
Source

K8s services

Summary

In this chapter, we just go over a very basic example using k8s services.

We have a server written in Go that runs 2 different versions of an API.

Services rely upon the label and selector constructs

We also get familiar with 2 useful tools: kubectl port-forward and kubectl get endpoints.

By default, kubectl operates within the default namespace. This is fine for testing purposes but feel free to create a new namespace and work within that if you do so choose.

Workshop

Ensure you have setup kuebctl and minikube properly

I highly recommend disconnecting from the VPN

Please ensure that kubectl is using the correct context

$ kubectl config current-context
minikube

If the above command doesn't return minikube, please walkthrough the minikube installation instructions one more time to make sure everything was set up properly or contact infra for assistance.

Allow minikube to use your local docker images
$ eval $(minikube docker-env)

Note that you will need to run the above command whenever you interact with a new shell for the changes to be applied

Build the docker image
code/k8s-for-app-devs/workshops/session1 $ docker build -t coolapp .
Apply the k8s manifests
code/k8s-for-app-devs/workshops/session1 $ kubectl apply -f k8s/coolappv1-deployment.yaml
code/k8s-for-app-devs/workshops/session1 $ kubectl apply -f k8s/coolappv2-deployment.yaml
code/k8s-for-app-devs/workshops/session1 $ kubectl apply -f k8s/service.yaml

You can inspect the various resources we have created using kubectl to find out more

$ kubectl get deployment coolapp-v1
$ kubectl get deployment coolapp-v2
$ kubectl get service coolapp

# can try using the following tricks to get more information about a resource (works with deployments, services, and more)
$ kubectl get deployment coolapp-v1 -o json # also supports yaml
$ kubectl describe deployment coolapp-v1
Port-forwarding
$ kubectl port-forward svc/coolapp 8080:8080

# can open up a new shell or a browser to test
$ curl localhost:8080
Kubectl edit

Stop the port-forwarding. It's time to modify the service so that we can start serving the superior version 2 of this application.

At the beginning of this workshop, the selector looks like

selector:
  app: coolapp
  version: v1

Now we want to change it to

selector:
  app: coolapp
  version: v2

We have 2 options to choose from to make this change.

1. Kubectl edit

Kubectl edit allows a user to modify a resource directly using a specified text editor. The change will be applied after saving and exiting the editor.

$ kubectl edit service coolapp

By default, this uses the vi text editor. This can be changed by reading the docs

2. Kubectl apply

You also have the option of modifying the service.yaml and updating the selector in that file.

code/k8s-for-app-devs/workshops/session1 $ kubectl apply -f k8s/service.yaml
Kubernetes endpoints

Endpoints are one of the lower level abstractions that support Kubernetes services. As you make changes to the service selector, I recommend running

kubectl get endpoints

in order to see how the changes manifests. Try the following

1. Modify the service to point at v1 coolapp (should see 3 ip addresses)
2. Modify the service to point at v2 coolapp (should see 3 different ip addresses)
3. Modfiy the service to point at neither v1 coolapp nor v2 coolapp (should see 0 ip addresses)

References

Slides Official Kubernetes Service Documentation

FAQs

Package last updated on 02 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc