Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Converting from Docker-Compose

The first step will be to install kompose and convert our docker-compose.yml to kubernetes yaml files.

Install kompose

> brew install kompose

Startup without Converting

For simple docker-compose files, we can skip the steps pf converting and start up directly using kompose up.Start up directly

> kompose up

Exporting

Export docker-compose For more complicated docker-compose files, we will need to export and then modify the converted files.

> kompose convert


Code Block
$ kompose convert
WARN Volume mount on the host "/Users/john.mehan/projects/cloud/deployment/is-config/IND" isn't supported - ignoring path on the host 
INFO Kubernetes file "cloudservice-service.yaml" created 
INFO Kubernetes file "isservice-service.yaml" created 
INFO Kubernetes file "postgres-service.yaml" created 
INFO Kubernetes file "redis-service.yaml" created 
INFO Kubernetes file "cloudservice-deployment.yaml" created 
INFO Kubernetes file "isservice-deployment.yaml" created 
INFO Kubernetes file "isservice-claim0-persistentvolumeclaim.yaml" created 
INFO Kubernetes file "postgres-deployment.yaml" created 
INFO Kubernetes file "db-volume-persistentvolumeclaim.yaml" created 
INFO Kubernetes file "redis-deployment.yaml" created 


Create

...

Kubernetes pods in Cluster

We are using minkube for our cluster. Lets start by making sure it is running:

Might have to have minikube up and running for this to work

> minikube start

Code Block
$ minikube start


Using the yaml files created by kompose export, lets create our pods:

Code Block



$ kubectl create -f cloudservice-service.yaml,isservice-service.yaml,postgres-service.yaml,redis-service.yaml,cloudservice-deployment.yaml,isservice-deployment.yaml,isservice-claim0-persistentvolumeclaim.yaml,postgres-deployment.yaml,db-volume-persistentvolumeclaim.yaml,redis-deployment.yaml 

service/cloudservice created
service/isservice created
service/postgres created
service/redis created
deployment.extensions/cloudservice created
deployment.extensions/isservice created
persistentvolumeclaim/isservice-claim0 created
deployment.extensions/postgres created
persistentvolumeclaim/db-volume created
deployment.extensions/redis created

Expose a service

> kubectl expose deployment cloudservice --type=NodePort --name=cload-service

Pulling image from Docker Registry

Kubernetes will pull docker images from docker hub by default. For our own custom images, we will pull them from our local docker registry.

For this to work we need to

  • create a secret in the cluster that holds our authorization token
  • update our deployment yaml files to include this secret
  • setup an ssh tunnel between our localhost running docker registry and our cluster (minikube)

Create a Secret in the cluster that holds your authorization token

> kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>


Code Block
kubectl create secret docker-registry regcred --docker-server=http://localhost:5000/ --docker-username=username --docker-password=password --docker-email=john.mehan@irdeto.com
secret/regcred created

Revise deployment.yaml files

Add imagePullSecrets section to your deployment yaml files:


imagePullSecrets:
- name: regcred

example:

Code Block
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
...
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: isservice
    spec:
      containers:
      - image: localhost:5000/safa_is:0.1
        name: isservice
        ports:
        - containerPort: 8080
Code Block
$ kubectl expose deployment cloudservice --type=NodePort --name=cload-service
service/cload-service exposed


$ kubectl get services

NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
cload-service    NodePort    10.105.166.253   <none>        8080:32696/TCP   5s
cloudservice     ClusterIP   10.107.194.8     <none>        80/TCP           37m
hello-minikube   NodePort    10.106.20.131    <none>        8080resources:32733/TCP   224d
isservice {}
        ClusterIP   10.101.181.189tty: true
   <none>        7080/TCP         37m
kubernetesvolumeMounts:
       ClusterIP -  10.96.0.1        <none>        443/TCP          224d
postgresmountPath: /home/irdeto/CONF/ISF/IND
         ClusterIP name:  10.105.249.194is-volume
    <none>  restartPolicy: Always
     5432/TCP volumes:
      - name: 37mis-volume
redis        persistentVolumeClaim:
    ClusterIP   10.98.155.80   claimName: is-volume
 <none>     imagePullSecrets:
   6379/TCP   - name:     37m

Pulling image from Docker Registry

Create a Secret in the cluster that holds your authorization token

> kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>

regcred
status: {}


Setup SSH Tunnel

We will setup an SSH Tunnel in order to allow kubernetes to pull images from our local docker registry.

Code Block
ssh -i ~/.minikube/machines/minikube/id_rsa docker@$(minikube ip) -R 5000:localhost:5000
Code Block
kubectl create secret docker-registry regcred --docker-server=http://localhost:5000/ --docker-username=username --docker-password=password --docker-email=john.mehan@irdeto.com
secret/regcred created





References

...