Skip to content

Instantly share code, notes, and snippets.

@rcherara
Last active December 12, 2018 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcherara/c3352c54c1ae266eb1f650fcc0061cc8 to your computer and use it in GitHub Desktop.
Save rcherara/c3352c54c1ae266eb1f650fcc0061cc8 to your computer and use it in GitHub Desktop.
Build container with deployment on Kubernetes

Building the Docker image rest-rcherara"

$ docker build . -t rest-rcherara

List docker images

$ docker image ls
  REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
  rest-rcherara                              latest              845c64a35182        4 minutes ago       206MB

Run docker image

$ docker run -p 7680:7680 -it rest-rcherara

Push docker image to Docker Hub

$ docker login
$ docker tag 845c64a35182 mydockerreddah/rest-rcherara
$ docker push mydockerreddah/rest-rcherara    

Creating service, list all services and show service description on Kubernetes

$ kubectl create -f service.yml
$ kubectl get services --all-namespaces
$ kubectl describe service rest-example

Creating a deployment on Kubernetes

$ kubectl create -f deployment.yml
$ kubectl describe deployment rest-example
$ kubectl get pods
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: rest-example
spec:
replicas: 1
template:
metadata:
labels:
app: rest-example
tier: backend
spec:
containers:
- name: rest-rcherara
image: mydockerreddah/rest-rcherara
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
ports:
- containerPort: 7680
FROM jeanblanchard/java:8
LABEL environement="dev" service="book" owner="rcherara"
LABEL Description="This image is used to start the rest-example executable" Vendor="API Books" Version="1.0"
MAINTAINER rcherara
WORKDIR /opt/rest-example/
COPY target/rest-example-0.1.0.jar rest-example-0.1.0.jar
CMD java -jar rest-example-0.1.0.jar
EXPOSE 7680
apiVersion: v1
kind: Service
metadata:
name: rest-example
labels:
app: rest-example
tier: backend
spec:
type: NodePort
ports:
# the port that this service should serve on
- port: 7680
selector:
app: rest-example
tier: backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment