Pre-requisites:
K8S cluster setup and running.
If you have not done this before, first check my post for setting the K8s cluster
https://jinojoseph.blogspot.com/2019/10/installing-k8s-as-cluster-using-kubeadm.html
Once you have done that what if you need to build and run your own image?
You're going to need to push your image to a registry that is accessible to Kubernetes. The obvious option is to use the Docker Hub, but what if you want to keep your image private?
The answer: run a registry inside the Kubernetes cluster itself. This way there's no need to worry about hidden costs or pushing to external resources. You can use the default Docker registry for this purpose, but to do this securely requires setting up TLS certificates and manual twiddling. A simpler option is to install the Trow registry via its install script, which will also take care of configuring TLS correctly.
K8S cluster setup and running.
If you have not done this before, first check my post for setting the K8s cluster
https://jinojoseph.blogspot.com/2019/10/installing-k8s-as-cluster-using-kubeadm.html
Once you have done that what if you need to build and run your own image?
You're going to need to push your image to a registry that is accessible to Kubernetes. The obvious option is to use the Docker Hub, but what if you want to keep your image private?
The answer: run a registry inside the Kubernetes cluster itself. This way there's no need to worry about hidden costs or pushing to external resources. You can use the default Docker registry for this purpose, but to do this securely requires setting up TLS certificates and manual twiddling. A simpler option is to install the Trow registry via its install script, which will also take care of configuring TLS correctly.
#
git clone https://github.com/ContainerSolutions/trow.git
# cd trow
# ./install.sh
Trow AutoInstaller for Kubernetes
=================================
This installer assumes kubectl is configured to point to the cluster you want to
install Trow on and that your user has cluster-admin rights.
This installer will perform the following steps:
- Create a ServiceAccount and associated Roles for Trow
- Create a Kubernetes Service and Deployment
- Request and sign a TLS certificate for Trow from the cluster CA
- Copy the public certificate to all nodes in the cluster
- Copy the public certificate to this machine (optional)
- Register a ValidatingAdmissionWebhook (optional)
If you're running on GKE, you may first need to give your user cluster-admin
rights:
$ kubectl create clusterrolebinding cluster-admin-binding --clusterrole=cluster-admin --user=
Where is your user, normally the e-mail address you use with your GKE
account.
Do you want to continue? (y/n) y
Starting Kubernetes Resources
serviceaccount/trow created
role.rbac.authorization.k8s.io/trow created
clusterrole.rbac.authorization.k8s.io/trow created
rolebinding.rbac.authorization.k8s.io/trow created
clusterrolebinding.rbac.authorization.k8s.io/trow created
deployment.apps/trow-deploy created
service/trow created
Approving certificate. This may take some time.
..................
Copying certs to nodes
job.batch/copy-certs-34454354-0f89-4781-ba02-465656 created
job.batch/copy-certs-34543543-1deb-4a64-ab00-45656 created
Do you wish to install certs on this host and configure /etc/hosts to allow access from this machine? (y/n) y
Copying cert into Docker
This requires sudo privileges
-----BEGIN CERTIFICATE-----
MIIEzjCCA7agAwIBAgIUCABTopWBLO6D1RpXH5Rk9M6kzxswDQYJKoZIhvcNAQEL
BQAwFTETMBEGA1UEAxMKa3ViZXJuZXRlczAeFw0xOTEwMTYwNjQwMDBaFw0yMDEw
msgmYvMUKsnLyzAMs85GQecC74ELD0uU8NnvAoRa1a8NAfIWmpXLhYQQiU0JYnbN
xJCEYXSVCQIDAQABo4IBDjCCAQowDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoG
CCsGAQUFBwMBMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFAEgnXOeOnJA9Kbo/bp3
DZuvu6kOMIG1BgNVHREEga0wgaqCInRyb3cua3ViZS1wdWJsaWMuc3ZjLmNsdXN0
==
-----END CERTIFICATE-----
Successfully copied cert
Adding entry to /etc/hosts for trow.kube-public
No external IP listed in "kubectl get nodes -o wide"
Trying minikube
Not minikube.
Trying internal IP which may work for local clusters e.g. microk8s
Exposing registry via /etc/hosts
This requires sudo privileges
10.0.1.12 trow.kube-public # added for trow registry
Successfully configured localhost
Do you want to configure Trow as a validation webhook (NB this will stop external images from being deployed to the cluster)? (y/n) n
#
Testing:
---------
ubuntu@namenode:~$ sudo docker pull nginx:latest
latest: Pulling from library/nginx
b8f262c62ec6: Pull complete
e9218e8f93b1: Pull complete
7acba7289aa3: Pull complete
Digest: sha256:aeded0f2d2b11fcc7fcadc16ccd1
Status: Downloaded newer image for nginx:latest
ubuntu@namenode:~$
ubuntu@namenode:~$
ubuntu@namenode:~$ sudo docker tag nginx:latest trow.kube-public:31000/mynginx:test
ubuntu@namenode:~$
ubuntu@namenode:~$ sudo docker push trow.kube-public:31000/mynginx:test
The push refers to repository [trow.kube-public:31000/mynginx]
509a5ea4aeeb: Pushed
3bb51901dfa3: Pushed
2db44bce66cd: Pushed
test: digest: sha256:dbdfa744f53d596f7bae34540 size: 928
ubuntu@namenode:~$
ubuntu@namenode:~$
ubuntu@namenode:~$ kubectl run trow-nginx --image=trow.kube-public:31000/mynginx:test
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/trow-nginx created
ubuntu@namenode:~$
ubuntu@namenode:~$
ubuntu@namenode:~$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
trow-nginx 1/1 1 1 38s
Comments