DEV Community

Cover image for How (not) to install WordPress on Kubernetes đź’©
Chun Fei Lung
Chun Fei Lung

Posted on • Updated on • Originally published at chuniversiteit.nl

How (not) to install WordPress on Kubernetes đź’©

Steer clear from unnecessary complexity by running everything in a single container

Today we’re dragging LAMP into the 21st century in the worst possible way.

Much of the world wide web reportedly runs on PHP. This includes large online platforms, like Facebook, Flickr, and Wikipedia, but also a countless number of WordPress-based corporate websites and personal blogs.

This does not mean that PHP is a popular programming language. In fact, it’s probably one of the most ridiculed languages on the internet (*). WordPress’s reputation isn’t exactly stellar among web
developers either.

(*) The other one being its stupid cousin, JavaScript. Nowadays JavaScript gets lots of love though.

EvErYtHiNg WaS bEtTeR iN tHe PaSt

Now, there are a lot of reasons to hate on PHP (and WordPress). Some of those are perfectly justified. Most however are based on negative experiences that people once had with some version of the language or ecosystem that hasn’t existed for a very long time now.

The language, its interpreter, community, and ecosystem have all made huge leaps forward, to the point where everything about it is basically just a slightly different Java. Things are pretty okay nowadays.

But sometimes I do long for the “good old days”, when you could still get away with absolutely awful spaghetti code without tests, debug code by (repeatedly) adding var_dump()s to your PHP files on production, and deploy new code by just FTP’ing a bunch of files to the right directory.

Today, we’re going to use modern development and hosting tools to relive those good old days – or at least parts of it. We’ll do this by packaging WordPress and some other stuff into a Docker container and hosting it on a local Kubernetes cluster as if it is a virtual machine.

Packaging our app

The first thing we need is Docker, a tool that lets you run your code in containers. A container contains your code and an operating system, so it is kind of like a virtual machine, except that it is not a virtual machine.

Containers can be provisioned using a so-called Dockerfile. A Dockerfile is sort of like a shell script, except that it is not a shell script.

One major difference between shell scripts and Dockerfiles, is that Dockerfiles also specify which operating system you’ll use. In our case, we’ll go with the latest LTS version of Ubuntu, for no reason other than that it is a popular choice among those who maintain actual virtual machines:

FROM ubuntu:20.04
Enter fullscreen mode Exit fullscreen mode

Almost everything after this line looks a lot like a shell script, albeit one with a slightly more convoluted syntax. For example, this is how we install the packages that we need in our container:

# Make sure that we don’t get annoying prompts
ARG DEBIAN_FRONTEND=noninteractive

# Install our best friends; Apache, MySQL, and PHP. And also some other stuff
# that we may or may not need
RUN apt update \
    && \
    apt install -y \
    wordpress \
    php \
    libapache2-mod-php \
    mysql-server \
    php-mysql \
    php-mbstring \
    php-zip \
    php-gd \
    php-json \
    php-curl \
    phpmyadmin \
    htop \
    less \
    vim \
    sl \
    && \
    ln -s /usr/games/sl /usr/bin/sl
Enter fullscreen mode Exit fullscreen mode

Note that we put everything into a single RUN instruction. This is something that you see often in Dockerfiles, because it’s a best practice.

(**) Of course, in reality it’s a bit more nuanced than that. You can always check out Docker’s documentation of best practices if you need a real guide.

Since we’re not particularly interested in following best (or even acceptable) practices in this guide we’ll just use individual instructions as much as possible, if only because I think it looks prettier.

Anyway, in the previous snippet we used apt to install two web applications: WordPress and phpMyAdmin. We still need to configure them so that they can be accessed via Apache and know how to connect to the database:

# Configure Apache so that it can serve WordPress and phpMyadmin
COPY wordpress.conf /etc/apache2/sites-available/wordpress.conf
COPY phpmyadmin.conf /etc/apache2/sites-available/phpmyadmin.conf

# Make sure that Apache will actually serve our applications
RUN a2ensite wordpress
RUN a2ensite phpmyadmin
RUN a2enmod rewrite

# Create database accounts
RUN service mysql start \
    && \
    mysql -e 'CREATE DATABASE wordpress;' \
    && \
    mysql -e "CREATE USER wordpress@localhost IDENTIFIED BY 'wordpress';" \
    && \
    mysql -e "GRANT ALL ON wordpress.* TO wordpress@localhost;" \
    && \
    mysql -e "CREATE USER phpmyadmin@localhost IDENTIFIED BY 'phpmyadmin';" \
    && \
    mysql -e "GRANT ALL ON *.* TO phpmyadmin@localhost;" \
    && \
    mysql -e "CREATE USER pma@localhost IDENTIFIED BY 'pmapass';" \
    && \
    mysql -e "GRANT ALL ON *.* TO pma@localhost;" \
    && \
    mysql -e 'FLUSH PRIVILEGES;'

# Configure applications with database credentials
COPY phpmyadmin-config.php /etc/phpmyadmin/config-db.php
COPY wordpress-config.php /etc/wordpress/config-localhost.php
Enter fullscreen mode Exit fullscreen mode

As you can see, I took the liberty of hardcoding some credentials that are easy to remember, so you’ll never have to worry about locking yourself out of the system!

Speaking of which, we’ll also pretend that we care about security by installing and configuring ufw so that it allows traffic for ports between 1 and 443 (which we do not actually use in this guide, but whatever):

# This doesn’t do much, but at least we’ve installed and configured something
RUN apt install -y ufw
RUN ufw allow 1:443/tcp

# Why would you want this? I don’t know, but let’s do it anyway
EXPOSE 1
EXPOSE 2
EXPOSE 3
EXPOSE 4
EXPOSE 5
EXPOSE 6
EXPOSE 7
EXPOSE 8
EXPOSE 9
EXPOSE 10
EXPOSE 11
EXPOSE 12
EXPOSE 13
EXPOSE 14
EXPOSE 15
EXPOSE 16
EXPOSE 17
EXPOSE 18
EXPOSE 19
EXPOSE 20
EXPOSE 21
EXPOSE 22
EXPOSE 23
EXPOSE 24
EXPOSE 25
EXPOSE 26
EXPOSE 27
EXPOSE 28
EXPOSE 29
EXPOSE 30
EXPOSE 31
# I may have omitted a line or 412 here
Enter fullscreen mode Exit fullscreen mode

There is one very important thing that we haven’t done yet: we still need to start the Apache web server using CMD, which is sort of like RUN, except that it’s the thing that is executed when the container is actually running.

There are also two other very important things.

Remember that MySQL server that we had started earlier so that we could create some database users? It’s no longer up at this point, so we’ll need to start it again as well.

Moreover, Docker containers stop when their main process stops. In our case, we want to start two perpetually running processes via service start. However, these commands exit once they have started the service in the background and thus so will our container.

Fortunately, we can easily keep our Docker container alive by keeping it comatose until the end of time by adding sleep infinity to our CMD instruction:

CMD \
    service apache2 start \
    && \
    service mysql start \
    && \
    sleep infinity

Enter fullscreen mode Exit fullscreen mode

The resulting Dockerfile can be found in the accompanying GitHub repository, along with the various configuration files that were referenced in the snippets above.

We can build a container by executing the following command in the directory that contains the Dockerfile and configuration files for WordPress and phpMyAdmin:

docker build -t chunfeilung/kubernutty .
Enter fullscreen mode Exit fullscreen mode

The -t chunfeilung/kubernutty part is used to name the container, which you can also find on Docker Hub.

Run our app with Docker

Our container can be started by executing the following command:

docker run -d -P -p 80:80 chunfeilung/kubernutty
Enter fullscreen mode Exit fullscreen mode

This will take a few seconds. Not only because the container needs to start multiple services, but also because we have exposed an obscene number of ports | I have since learned that exposing too many ports is a very effective way to off the Docker daemon. in our Dockerfile.

It’s worth the wait though; the end result looks glorious in docker ps! The formatted output below is reasonably close to what I’m seeing on my screen.

Article continues below big-ass code block

CONTAINER ID   IMAGE                    COMMAND                  CREATED        
  STATUS         PORTS                                                          










































































































































































































































                                             NAMES 85c102059687   chunfeilung/ku
bernutty   "/bin/sh -c 'service…"   33 seconds ago   Up 3 seconds   0.0.0.0:80->
80/tcp, :::80->80/tcp, 0.0.0.0:58967->1/tcp, :::58968->1/tcp, 0.0.0.0:58966->2/t
cp, :::58967->2/tcp, 0.0.0.0:58965->3/tcp, :::58966->3/tcp, 0.0.0.0:58964->4/tcp
, :::58965->4/tcp, 0.0.0.0:58963->5/tcp, :::58964->5/tcp, 0.0.0.0:58962->6/tcp, 
:::58963->6/tcp, 0.0.0.0:58961->7/tcp, :::58962->7/tcp, 0.0.0.0:58960->8/tcp, ::
:58961->8/tcp, 0.0.0.0:58959->9/tcp, :::58960->9/tcp, 0.0.0.0:58958->10/tcp, :::
58959->10/tcp, 0.0.0.0:58957->11/tcp, :::58958->11/tcp, 0.0.0.0:58956->12/tcp, :
::58957->12/tcp, 0.0.0.0:58955->13/tcp, :::58956->13/tcp, 0.0.0.0:58954->14/tcp,
 :::58955->14/tcp, 0.0.0.0:58953->15/tcp, :::58954->15/tcp, 0.0.0.0:58952->16/tc
p, :::58953->16/tcp, 0.0.0.0:58951->17/tcp, :::58952->17/tcp, 0.0.0.0:58950->18/
tcp, :::58951->18/tcp, 0.0.0.0:58949->19/tcp, :::58950->19/tcp, 0.0.0.0:58948->2
0/tcp, :::58949->20/tcp, 0.0.0.0:58947->21/tcp, :::58948->21/tcp, 0.0.0.0:58946-
>22/tcp, :::58947->22/tcp, 0.0.0.0:58945->23/tcp, :::58946->23/tcp, 0.0.0.0:5894
4->24/tcp, :::58945->24/tcp, 0.0.0.0:58943->25/tcp, :::58944->25/tcp, 0.0.0.0:58
942->26/tcp, :::58943->26/tcp, 0.0.0.0:58941->27/tcp, :::58942->27/tcp, 0.0.0.0:
58940->28/tcp, :::58941->28/tcp, 0.0.0.0:58939->29/tcp, :::58940->29/tcp, 0.0.0.
0:58938->30/tcp, :::58939->30/tcp, 0.0.0.0:58937->31/tcp, :::58938->31/tcp, 0.0.
0.0:58936->32/tcp, :::58937->32/tcp, 0.0.0.0:58935->33/tcp, :::58936->33/tcp, 0.
0.0.0:58934->34/tcp, :::58935->34/tcp, 0.0.0.0:58933->35/tcp, :::58934->35/tcp, 
0.0.0.0:58932->36/tcp, :::58933->36/tcp, 0.0.0.0:58931->37/tcp, :::58932->37/tcp
, 0.0.0.0:58930->38/tcp, :::58931->38/tcp, 0.0.0.0:58929->39/tcp, :::58930->39/t
cp, 0.0.0.0:58928->40/tcp, :::58929->40/tcp, 0.0.0.0:58927->41/tcp, :::58928->41
/tcp, 0.0.0.0:58926->42/tcp, :::58927->42/tcp, 0.0.0.0:58925->43/tcp, :::58926->
43/tcp, 0.0.0.0:58924->44/tcp, :::58925->44/tcp, 0.0.0.0:58923->45/tcp, :::58924
->45/tcp, 0.0.0.0:58922->46/tcp, :::58923->46/tcp, 0.0.0.0:58921->47/tcp, :::589
22->47/tcp, 0.0.0.0:58920->48/tcp, :::58921->48/tcp, 0.0.0.0:58919->49/tcp, :::5
8920->49/tcp, 0.0.0.0:58918->50/tcp, :::58919->50/tcp, 0.0.0.0:58917->51/tcp, ::
:58918->51/tcp, 0.0.0.0:58916->52/tcp, :::58917->52/tcp, 0.0.0.0:58915->53/tcp, 
:::58916->53/tcp, 0.0.0.0:58914->54/tcp, :::58915->54/tcp, 0.0.0.0:58913->55/tcp
, :::58914->55/tcp, 0.0.0.0:58912->56/tcp, :::58913->56/tcp, 0.0.0.0:58911->57/t
cp, :::58912->57/tcp, 0.0.0.0:58910->58/tcp, :::58911->58/tcp, 0.0.0.0:58909->59
/tcp, :::58910->59/tcp, 0.0.0.0:58908->60/tcp, :::58909->60/tcp, 0.0.0.0:58907->
61/tcp, :::58908->61/tcp, 0.0.0.0:58906->62/tcp, :::58907->62/tcp, 0.0.0.0:58905
->63/tcp, :::58906->63/tcp, 0.0.0.0:58904->64/tcp, :::58905->64/tcp, 0.0.0.0:589
03->65/tcp, :::58904->65/tcp, 0.0.0.0:58902->66/tcp, :::58903->66/tcp, 0.0.0.0:5
8901->67/tcp, :::58902->67/tcp, 0.0.0.0:58900->68/tcp, :::58901->68/tcp, 0.0.0.0
:58899->69/tcp, :::58900->69/tcp, 0.0.0.0:58898->70/tcp, :::58899->70/tcp, 0.0.0
.0:58897->71/tcp, :::58898->71/tcp, 0.0.0.0:58896->72/tcp, :::58897->72/tcp, 0.0
.0.0:58895->73/tcp, :::58896->73/tcp, 0.0.0.0:58894->74/tcp, :::58895->74/tcp, 0
.0.0.0:58893->75/tcp, :::58894->75/tcp, 0.0.0.0:58892->76/tcp, :::58893->76/tcp,
 0.0.0.0:58891->77/tcp, :::58892->77/tcp, 0.0.0.0:58890->78/tcp, :::58891->78/tc
p, 0.0.0.0:58889->79/tcp, :::58890->79/tcp, 0.0.0.0:58888->81/tcp, :::58889->81/
tcp, 0.0.0.0:58887->82/tcp, :::58888->82/tcp, 0.0.0.0:58886->83/tcp, :::58887->8
3/tcp, 0.0.0.0:58885->84/tcp, :::58886->84/tcp, 0.0.0.0:58884->85/tcp, :::58885-
>85/tcp, 0.0.0.0:58883->86/tcp, :::58884->86/tcp, 0.0.0.0:58882->87/tcp, :::5888
3->87/tcp, 0.0.0.0:58881->88/tcp, :::58882->88/tcp, 0.0.0.0:58880->89/tcp, :::58
881->89/tcp, 0.0.0.0:58879->90/tcp, :::58880->90/tcp, 0.0.0.0:58878->91/tcp, :::
58879->91/tcp, 0.0.0.0:58877->92/tcp, :::58878->92/tcp, 0.0.0.0:58876->93/tcp, :
::58877->93/tcp, 0.0.0.0:58875->94/tcp, :::58876->94/tcp, 0.0.0.0:58874->95/tcp,
 :::58875->95/tcp, 0.0.0.0:58873->96/tcp, :::58874->96/tcp, 0.0.0.0:58872->97/tc
p, :::58873->97/tcp, 0.0.0.0:58871->98/tcp, :::58872->98/tcp, 0.0.0.0:58870->99/
tcp, :::58871->99/tcp, 0.0.0.0:58869->100/tcp, :::58870->100/tcp, 0.0.0.0:58868-
>101/tcp, :::58869->101/tcp, 0.0.0.0:58867->102/tcp, :::58868->102/tcp, 0.0.0.0:
58866->103/tcp, :::58867->103/tcp, 0.0.0.0:58865->104/tcp, :::58866->104/tcp, 0.
0.0.0:58864->105/tcp, :::58865->105/tcp, 0.0.0.0:58863->106/tcp, :::58864->106/t
cp, 0.0.0.0:58862->107/tcp, :::58863->107/tcp, 0.0.0.0:58861->108/tcp, :::58862-
>108/tcp, 0.0.0.0:58860->109/tcp, :::58861->109/tcp, 0.0.0.0:58859->110/tcp, :::
58860->110/tcp, 0.0.0.0:58858->111/tcp, :::58859->111/tcp, 0.0.0.0:58857->112/tc
p, :::58858->112/tcp, 0.0.0.0:58856->113/tcp, :::58857->113/tcp, 0.0.0.0:58855->
114/tcp, :::58856->114/tcp, 0.0.0.0:58854->115/tcp, :::58855->115/tcp, 0.0.0.0:5
8853->116/tcp, :::58854->116/tcp, 0.0.0.0:58852->117/tcp, :::58853->117/tcp, 0.0
.0.0:58851->118/tcp, :::58852->118/tcp, 0.0.0.0:58850->119/tcp, :::58851->119/tc
p, 0.0.0.0:58849->120/tcp, :::58850->120/tcp, 0.0.0.0:58848->121/tcp, :::58849->
121/tcp, 0.0.0.0:58847->122/tcp, :::58848->122/tcp, 0.0.0.0:58846->123/tcp, :::5
8847->123/tcp, 0.0.0.0:58845->124/tcp, :::58846->124/tcp, 0.0.0.0:58844->125/tcp
, :::58845->125/tcp, 0.0.0.0:58843->126/tcp, :::58844->126/tcp, 0.0.0.0:58842->1
27/tcp, :::58843->127/tcp, 0.0.0.0:58841->128/tcp, :::58842->128/tcp, 0.0.0.0:58
840->129/tcp, :::58841->129/tcp, 0.0.0.0:58839->130/tcp, :::58840->130/tcp, 0.0.
0.0:58838->131/tcp, :::58839->131/tcp, 0.0.0.0:58837->132/tcp, :::58838->132/tcp
, 0.0.0.0:58836->133/tcp, :::58837->133/tcp, 0.0.0.0:58835->134/tcp, :::58836->1
34/tcp, 0.0.0.0:58834->135/tcp, :::58835->135/tcp, 0.0.0.0:58833->136/tcp, :::58
834->136/tcp, 0.0.0.0:58832->137/tcp, :::58833->137/tcp, 0.0.0.0:58831->138/tcp,
 :::58832->138/tcp, 0.0.0.0:58830->139/tcp, :::58831->139/tcp, 0.0.0.0:58829->14
0/tcp, :::58830->140/tcp, 0.0.0.0:58828->141/tcp, :::58829->141/tcp, 0.0.0.0:588
27->142/tcp, :::58828->142/tcp, 0.0.0.0:58826->143/tcp, :::58827->143/tcp, 0.0.0
.0:58825->144/tcp, :::58826->144/tcp, 0.0.0.0:58824->145/tcp, :::58825->145/tcp,
 0.0.0.0:58823->146/tcp, :::58824->146/tcp, 0.0.0.0:58822->147/tcp, :::58823->14
7/tcp, 0.0.0.0:58821->148/tcp, :::58822->148/tcp, 0.0.0.0:58820->149/tcp, :::588
21->149/tcp, 0.0.0.0:58819->150/tcp, :::58820->150/tcp, 0.0.0.0:58818->151/tcp, 
:::58819->151/tcp, 0.0.0.0:58817->152/tcp, :::58818->152/tcp, 0.0.0.0:58816->153
/tcp, :::58817->153/tcp, 0.0.0.0:58815->154/tcp, :::58816->154/tcp, 0.0.0.0:5881
4->155/tcp, :::58815->155/tcp, 0.0.0.0:58813->156/tcp, :::58814->156/tcp, 0.0.0.
0:58812->157/tcp, :::58813->157/tcp, 0.0.0.0:58811->158/tcp, :::58812->158/tcp, 
0.0.0.0:58810->159/tcp, :::58811->159/tcp, 0.0.0.0:58809->160/tcp, :::58810->160
/tcp, 0.0.0.0:58808->161/tcp, :::58809->161/tcp, 0.0.0.0:58807->162/tcp, :::5880
8->162/tcp, 0.0.0.0:58806->163/tcp, :::58807->163/tcp, 0.0.0.0:58805->164/tcp, :
::58806->164/tcp, 0.0.0.0:58804->165/tcp, :::58805->165/tcp, 0.0.0.0:58803->166/
tcp, :::58804->166/tcp, 0.0.0.0:58802->167/tcp, :::58803->167/tcp, 0.0.0.0:58801
->168/tcp, :::58802->168/tcp, 0.0.0.0:58800->169/tcp, :::58801->169/tcp, 0.0.0.0
:58799->170/tcp, :::58800->170/tcp, 0.0.0.0:58798->171/tcp, :::58799->171/tcp, 0
.0.0.0:58797->172/tcp, :::58798->172/tcp, 0.0.0.0:58796->173/tcp, :::58797->173/
tcp, 0.0.0.0:58795->174/tcp, :::58796->174/tcp, 0.0.0.0:58794->175/tcp, :::58795
->175/tcp, 0.0.0.0:58793->176/tcp, :::58794->176/tcp, 0.0.0.0:58792->177/tcp, ::
:58793->177/tcp, 0.0.0.0:58791->178/tcp, :::58792->178/tcp, 0.0.0.0:58790->179/t
cp, :::58791->179/tcp, 0.0.0.0:58789->180/tcp, :::58790->180/tcp, 0.0.0.0:58788-
>181/tcp, :::58789->181/tcp, 0.0.0.0:58787->182/tcp, :::58788->182/tcp, 0.0.0.0:
58786->183/tcp, :::58787->183/tcp, 0.0.0.0:58785->184/tcp, :::58786->184/tcp, 0.
0.0.0:58784->185/tcp, :::58785->185/tcp, 0.0.0.0:58783->186/tcp, :::58784->186/t
cp, 0.0.0.0:58782->187/tcp, :::58783->187/tcp, 0.0.0.0:58781->188/tcp, :::58782-
>188/tcp, 0.0.0.0:58780->189/tcp, :::58781->189/tcp, 0.0.0.0:58779->190/tcp, :::
58780->190/tcp, 0.0.0.0:58778->191/tcp, :::58779->191/tcp, 0.0.0.0:58777->192/tc
p, :::58778->192/tcp, 0.0.0.0:58776->193/tcp, :::58777->193/tcp, 0.0.0.0:58775->
194/tcp, :::58776->194/tcp, 0.0.0.0:58774->195/tcp, :::58775->195/tcp, 0.0.0.0:5
8773->196/tcp, :::58774->196/tcp, 0.0.0.0:58772->197/tcp, :::58773->197/tcp, 0.0
.0.0:58771->198/tcp, :::58772->198/tcp, 0.0.0.0:58770->199/tcp, :::58771->199/tc
p, 0.0.0.0:58769->200/tcp, :::58770->200/tcp, 0.0.0.0:58768->201/tcp, :::58769->
201/tcp, 0.0.0.0:58767->202/tcp, :::58768->202/tcp, 0.0.0.0:58766->203/tcp, :::5
8767->203/tcp, 0.0.0.0:58765->204/tcp, :::58766->204/tcp, 0.0.0.0:58764->205/tcp
, :::58765->205/tcp, 0.0.0.0:58763->206/tcp, :::58764->206/tcp, 0.0.0.0:58762->2
07/tcp, :::58763->207/tcp, 0.0.0.0:58761->208/tcp, :::58762->208/tcp, 0.0.0.0:58
760->209/tcp, :::58761->209/tcp, 0.0.0.0:58759->210/tcp, :::58760->210/tcp, 0.0.
0.0:58758->211/tcp, :::58759->211/tcp, 0.0.0.0:58757->212/tcp, :::58758->212/tcp
, 0.0.0.0:58756->213/tcp, :::58757->213/tcp, 0.0.0.0:58755->214/tcp, :::58756->2
14/tcp, 0.0.0.0:58754->215/tcp, :::58755->215/tcp, 0.0.0.0:58753->216/tcp, :::58
754->216/tcp, 0.0.0.0:58752->217/tcp, :::58753->217/tcp, 0.0.0.0:58751->218/tcp,
 :::58752->218/tcp, 0.0.0.0:58750->219/tcp, :::58751->219/tcp, 0.0.0.0:58749->22
0/tcp, :::58750->220/tcp, 0.0.0.0:58748->221/tcp, :::58749->221/tcp, 0.0.0.0:587
47->222/tcp, :::58748->222/tcp, 0.0.0.0:58746->223/tcp, :::58747->223/tcp, 0.0.0
.0:58745->224/tcp, :::58746->224/tcp, 0.0.0.0:58744->225/tcp, :::58745->225/tcp,
 0.0.0.0:58743->226/tcp, :::58744->226/tcp, 0.0.0.0:58742->227/tcp, :::58743->22
7/tcp, 0.0.0.0:58741->228/tcp, :::58742->228/tcp, 0.0.0.0:58740->229/tcp, :::587
41->229/tcp, 0.0.0.0:58739->230/tcp, :::58740->230/tcp, 0.0.0.0:58738->231/tcp, 
:::58739->231/tcp, 0.0.0.0:58737->232/tcp, :::58738->232/tcp, 0.0.0.0:58736->233
/tcp, :::58737->233/tcp, 0.0.0.0:58735->234/tcp, :::58736->234/tcp, 0.0.0.0:5873
4->235/tcp, :::58735->235/tcp, 0.0.0.0:58733->236/tcp, :::58734->236/tcp, 0.0.0.
0:58732->237/tcp, :::58733->237/tcp, 0.0.0.0:58731->238/tcp, :::58732->238/tcp, 
0.0.0.0:58730->239/tcp, :::58731->239/tcp, 0.0.0.0:58729->240/tcp, :::58730->240
/tcp, 0.0.0.0:58728->241/tcp, :::58729->241/tcp, 0.0.0.0:58727->242/tcp, :::5872
8->242/tcp, 0.0.0.0:58726->243/tcp, :::58727->243/tcp, 0.0.0.0:58725->244/tcp, :
::58726->244/tcp, 0.0.0.0:58724->245/tcp, :::58725->245/tcp, 0.0.0.0:58723->246/
tcp, :::58724->246/tcp, 0.0.0.0:58722->247/tcp, :::58723->247/tcp, 0.0.0.0:58721
->248/tcp, :::58722->248/tcp, 0.0.0.0:58720->249/tcp, :::58721->249/tcp, 0.0.0.0
:58719->250/tcp, :::58720->250/tcp, 0.0.0.0:58718->251/tcp, :::58719->251/tcp, 0
.0.0.0:58717->252/tcp, :::58718->252/tcp, 0.0.0.0:58716->253/tcp, :::58717->253/
tcp, 0.0.0.0:58715->254/tcp, :::58716->254/tcp, 0.0.0.0:58714->255/tcp, :::58715
->255/tcp, 0.0.0.0:58713->256/tcp, :::58714->256/tcp, 0.0.0.0:58712->257/tcp, ::
:58713->257/tcp, 0.0.0.0:58711->258/tcp, :::58712->258/tcp, 0.0.0.0:58710->259/t
cp, :::58711->259/tcp, 0.0.0.0:58709->260/tcp, :::58710->260/tcp, 0.0.0.0:58708-
>261/tcp, :::58709->261/tcp, 0.0.0.0:58707->262/tcp, :::58708->262/tcp, 0.0.0.0:
58706->263/tcp, :::58707->263/tcp, 0.0.0.0:58705->264/tcp, :::58706->264/tcp, 0.
0.0.0:58704->265/tcp, :::58705->265/tcp, 0.0.0.0:58703->266/tcp, :::58704->266/t
cp, 0.0.0.0:58702->267/tcp, :::58703->267/tcp, 0.0.0.0:58701->268/tcp, :::58702-
>268/tcp, 0.0.0.0:58700->269/tcp, :::58701->269/tcp, 0.0.0.0:58699->270/tcp, :::
58700->270/tcp, 0.0.0.0:58698->271/tcp, :::58699->271/tcp, 0.0.0.0:58697->272/tc
p, :::58698->272/tcp, 0.0.0.0:58696->273/tcp, :::58697->273/tcp, 0.0.0.0:58695->
274/tcp, :::58696->274/tcp, 0.0.0.0:58694->275/tcp, :::58695->275/tcp, 0.0.0.0:5
8693->276/tcp, :::58694->276/tcp, 0.0.0.0:58692->277/tcp, :::58693->277/tcp, 0.0
.0.0:58691->278/tcp, :::58692->278/tcp, 0.0.0.0:58690->279/tcp, :::58691->279/tc
p, 0.0.0.0:58689->280/tcp, :::58690->280/tcp, 0.0.0.0:58688->281/tcp, :::58689->
281/tcp, 0.0.0.0:58687->282/tcp, :::58688->282/tcp, 0.0.0.0:58686->283/tcp, :::5
8687->283/tcp, 0.0.0.0:58685->284/tcp, :::58686->284/tcp, 0.0.0.0:58684->285/tcp
, :::58685->285/tcp, 0.0.0.0:58683->286/tcp, :::58684->286/tcp, 0.0.0.0:58682->2
87/tcp, :::58683->287/tcp, 0.0.0.0:58681->288/tcp, :::58682->288/tcp, 0.0.0.0:58
680->289/tcp, :::58681->289/tcp, 0.0.0.0:58679->290/tcp, :::58680->290/tcp, 0.0.
0.0:58678->291/tcp, :::58679->291/tcp, 0.0.0.0:58677->292/tcp, :::58678->292/tcp
, 0.0.0.0:58676->293/tcp, :::58677->293/tcp, 0.0.0.0:58675->294/tcp, :::58676->2
94/tcp, 0.0.0.0:58674->295/tcp, :::58675->295/tcp, 0.0.0.0:58673->296/tcp, :::58
674->296/tcp, 0.0.0.0:58672->297/tcp, :::58673->297/tcp, 0.0.0.0:58671->298/tcp,
 :::58672->298/tcp, 0.0.0.0:58670->299/tcp, :::58671->299/tcp, 0.0.0.0:58669->30
0/tcp, :::58670->300/tcp, 0.0.0.0:58668->301/tcp, :::58669->301/tcp, 0.0.0.0:586
67->302/tcp, :::58668->302/tcp, 0.0.0.0:58666->303/tcp, :::58667->303/tcp, 0.0.0
.0:58665->304/tcp, :::58666->304/tcp, 0.0.0.0:58664->305/tcp, :::58665->305/tcp,
 0.0.0.0:58663->306/tcp, :::58664->306/tcp, 0.0.0.0:58662->307/tcp, :::58663->30
7/tcp, 0.0.0.0:58661->308/tcp, :::58662->308/tcp, 0.0.0.0:58660->309/tcp, :::586
61->309/tcp, 0.0.0.0:58659->310/tcp, :::58660->310/tcp, 0.0.0.0:58658->311/tcp, 
:::58659->311/tcp, 0.0.0.0:58657->312/tcp, :::58658->312/tcp, 0.0.0.0:58656->313
/tcp, :::58657->313/tcp, 0.0.0.0:58655->314/tcp, :::58656->314/tcp, 0.0.0.0:5865
4->315/tcp, :::58655->315/tcp, 0.0.0.0:58653->316/tcp, :::58654->316/tcp, 0.0.0.
0:58652->317/tcp, :::58653->317/tcp, 0.0.0.0:58651->318/tcp, :::58652->318/tcp, 
0.0.0.0:58650->319/tcp, :::58651->319/tcp, 0.0.0.0:58649->320/tcp, :::58650->320
/tcp, 0.0.0.0:58648->321/tcp, :::58649->321/tcp, 0.0.0.0:58647->322/tcp, :::5864
8->322/tcp, 0.0.0.0:58646->323/tcp, :::58647->323/tcp, 0.0.0.0:58645->324/tcp, :
::58646->324/tcp, 0.0.0.0:58644->325/tcp, :::58645->325/tcp, 0.0.0.0:58643->326/
tcp, :::58644->326/tcp, 0.0.0.0:58642->327/tcp, :::58643->327/tcp, 0.0.0.0:58641
->328/tcp, :::58642->328/tcp, 0.0.0.0:58640->329/tcp, :::58641->329/tcp, 0.0.0.0
:58639->330/tcp, :::58640->330/tcp, 0.0.0.0:58638->331/tcp, :::58639->331/tcp, 0
.0.0.0:58637->332/tcp, :::58638->332/tcp, 0.0.0.0:58636->333/tcp, :::58637->333/
tcp, 0.0.0.0:58635->334/tcp, :::58636->334/tcp, 0.0.0.0:58634->335/tcp, :::58635
->335/tcp, 0.0.0.0:58633->336/tcp, :::58634->336/tcp, 0.0.0.0:58632->337/tcp, ::
:58633->337/tcp, 0.0.0.0:58631->338/tcp, :::58632->338/tcp, 0.0.0.0:58630->339/t
cp, :::58631->339/tcp, 0.0.0.0:58629->340/tcp, :::58630->340/tcp, 0.0.0.0:58628-
>341/tcp, :::58629->341/tcp, 0.0.0.0:58627->342/tcp, :::58628->342/tcp, 0.0.0.0:
58626->343/tcp, :::58627->343/tcp, 0.0.0.0:58625->344/tcp, :::58626->344/tcp, 0.
0.0.0:58624->345/tcp, :::58625->345/tcp, 0.0.0.0:58623->346/tcp, :::58624->346/t
cp, 0.0.0.0:58622->347/tcp, :::58623->347/tcp, 0.0.0.0:58621->348/tcp, :::58622-
>348/tcp, 0.0.0.0:58620->349/tcp, :::58621->349/tcp, 0.0.0.0:58619->350/tcp, :::
58620->350/tcp, 0.0.0.0:58618->351/tcp, :::58619->351/tcp, 0.0.0.0:58617->352/tc
p, :::58618->352/tcp, 0.0.0.0:58616->353/tcp, :::58617->353/tcp, 0.0.0.0:58615->
354/tcp, :::58616->354/tcp, 0.0.0.0:58614->355/tcp, :::58615->355/tcp, 0.0.0.0:5
8613->356/tcp, :::58614->356/tcp, 0.0.0.0:58612->357/tcp, :::58613->357/tcp, 0.0
.0.0:58611->358/tcp, :::58612->358/tcp, 0.0.0.0:58610->359/tcp, :::58611->359/tc
p, 0.0.0.0:58609->360/tcp, :::58610->360/tcp, 0.0.0.0:58608->361/tcp, :::58609->
361/tcp, 0.0.0.0:58607->362/tcp, :::58608->362/tcp, 0.0.0.0:58606->363/tcp, :::5
8607->363/tcp, 0.0.0.0:58605->364/tcp, :::58606->364/tcp, 0.0.0.0:58604->365/tcp
, :::58605->365/tcp, 0.0.0.0:58603->366/tcp, :::58604->366/tcp, 0.0.0.0:58602->3
67/tcp, :::58603->367/tcp, 0.0.0.0:58601->368/tcp, :::58602->368/tcp, 0.0.0.0:58
600->369/tcp, :::58601->369/tcp, 0.0.0.0:58599->370/tcp, :::58600->370/tcp, 0.0.
0.0:58598->371/tcp, :::58599->371/tcp, 0.0.0.0:58597->372/tcp, :::58598->372/tcp
, 0.0.0.0:58596->373/tcp, :::58597->373/tcp, 0.0.0.0:58595->374/tcp, :::58596->3
74/tcp, 0.0.0.0:58594->375/tcp, :::58595->375/tcp, 0.0.0.0:58593->376/tcp, :::58
594->376/tcp, 0.0.0.0:58592->377/tcp, :::58593->377/tcp, 0.0.0.0:58591->378/tcp,
 :::58592->378/tcp, 0.0.0.0:58590->379/tcp, :::58591->379/tcp, 0.0.0.0:58589->38
0/tcp, :::58590->380/tcp, 0.0.0.0:58588->381/tcp, :::58589->381/tcp, 0.0.0.0:585
87->382/tcp, :::58588->382/tcp, 0.0.0.0:58586->383/tcp, :::58587->383/tcp, 0.0.0
.0:58585->384/tcp, :::58586->384/tcp, 0.0.0.0:58584->385/tcp, :::58585->385/tcp,
 0.0.0.0:58583->386/tcp, :::58584->386/tcp, 0.0.0.0:58582->387/tcp, :::58583->38
7/tcp, 0.0.0.0:58581->388/tcp, :::58582->388/tcp, 0.0.0.0:58580->389/tcp, :::585
81->389/tcp, 0.0.0.0:58579->390/tcp, :::58580->390/tcp, 0.0.0.0:58578->391/tcp, 
:::58579->391/tcp, 0.0.0.0:58577->392/tcp, :::58578->392/tcp, 0.0.0.0:58576->393
/tcp, :::58577->393/tcp, 0.0.0.0:58575->394/tcp, :::58576->394/tcp, 0.0.0.0:5857
4->395/tcp, :::58575->395/tcp, 0.0.0.0:58573->396/tcp, :::58574->396/tcp, 0.0.0.
0:58572->397/tcp, :::58573->397/tcp, 0.0.0.0:58571->398/tcp, :::58572->398/tcp, 
0.0.0.0:58570->399/tcp, :::58571->399/tcp, 0.0.0.0:58569->400/tcp, :::58570->400
/tcp, 0.0.0.0:58568->401/tcp, :::58569->401/tcp, 0.0.0.0:58567->402/tcp, :::5856
8->402/tcp, 0.0.0.0:58566->403/tcp, :::58567->403/tcp, 0.0.0.0:58565->404/tcp, :
::58566->404/tcp, 0.0.0.0:58564->405/tcp, :::58565->405/tcp, 0.0.0.0:58563->406/
tcp, :::58564->406/tcp, 0.0.0.0:58562->407/tcp, :::58563->407/tcp, 0.0.0.0:58561
->408/tcp, :::58562->408/tcp, 0.0.0.0:58560->409/tcp, :::58561->409/tcp, 0.0.0.0
:58559->410/tcp, :::58560->410/tcp, 0.0.0.0:58558->411/tcp, :::58559->411/tcp, 0
.0.0.0:58557->412/tcp, :::58558->412/tcp, 0.0.0.0:58556->413/tcp, :::58557->413/
tcp, 0.0.0.0:58555->414/tcp, :::58556->414/tcp, 0.0.0.0:58554->415/tcp, :::58555
->415/tcp, 0.0.0.0:58553->416/tcp, :::58554->416/tcp, 0.0.0.0:58552->417/tcp, ::
:58553->417/tcp, 0.0.0.0:58551->418/tcp, :::58552->418/tcp, 0.0.0.0:58550->419/t
cp, :::58551->419/tcp, 0.0.0.0:58549->420/tcp, :::58550->420/tcp, 0.0.0.0:58548-
>421/tcp, :::58549->421/tcp, 0.0.0.0:58547->422/tcp, :::58548->422/tcp, 0.0.0.0:
58546->423/tcp, :::58547->423/tcp, 0.0.0.0:58545->424/tcp, :::58546->424/tcp, 0.
0.0.0:58544->425/tcp, :::58545->425/tcp, 0.0.0.0:58543->426/tcp, :::58544->426/t
cp, 0.0.0.0:58542->427/tcp, :::58543->427/tcp, 0.0.0.0:58541->428/tcp, :::58542-
>428/tcp, 0.0.0.0:58540->429/tcp, :::58541->429/tcp, 0.0.0.0:58539->430/tcp, :::
58540->430/tcp, 0.0.0.0:58538->431/tcp, :::58539->431/tcp, 0.0.0.0:58537->432/tc
p, :::58538->432/tcp, 0.0.0.0:58536->433/tcp, :::58537->433/tcp, 0.0.0.0:58535->
434/tcp, :::58536->434/tcp, 0.0.0.0:58534->435/tcp, :::58535->435/tcp, 0.0.0.0:5
8533->436/tcp, :::58534->436/tcp, 0.0.0.0:58532->437/tcp, :::58533->437/tcp, 0.0
.0.0:58531->438/tcp, :::58532->438/tcp, 0.0.0.0:58530->439/tcp, :::58531->439/tc
p, 0.0.0.0:58529->440/tcp, :::58530->440/tcp, 0.0.0.0:58528->441/tcp, :::58529->
441/tcp, 0.0.0.0:58527->442/tcp, :::58528->442/tcp, 0.0.0.0:58526->443/tcp, :::5
8527->443/tcp   jovial_moser
Enter fullscreen mode Exit fullscreen mode

Things look pretty alright in the browser too.

http://localhost tells you that everything is fine:
Apache’s default welcome page that tells you that “It works!”

http://localhost/blog after we went through the installation process:
WordPress’s default home page that you see when you have completed the installation procedure.

http://localhost/phpmyadmin has a new theme nowadays, but somehow still looks as if it hasn’t been updated in 20 years:
phpMyAdmin’s home screen, which still looks as if it was designed by a programmer.

Deploy our app to Kubernetes

Good, we’re almost done! Let’s deploy our app to Kubernetes so we can call it a day.

First, create a kubernutty namespace for our project:

kubectl create namespace kubernutty
Enter fullscreen mode Exit fullscreen mode

Then, we’ll provide definitions for two types of Kubernetes objects that will help us deploy our WordPress container, a Deployment and a Service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubernutty
spec:
  replicas: 1
  selector:
    matchLabels:
      name: kubernutty
  template:
    metadata:
      labels:
        name: kubernutty
    spec:
      containers:
        - name: kubernutty
          image: chunfeilung/kubernutty
          ports:
            - containerPort: 80
          resources:
            requests:
              cpu: 1
              memory: 2G
            limits:
              cpu: 1
              memory: 2G
---
apiVersion: v1
kind: Service
metadata:
  name: kubernutty
spec:
  type: LoadBalancer
  ports:
    - name: http
      port: 80
  selector:
    name: kubernutty
Enter fullscreen mode Exit fullscreen mode

The Deployment tells us that we want to run a single instance of the chunfeilung/kubernutty image and give it access to 1 CPU and 2 gigabytes of memory. The Service makes the deployed application accessible within the Kubernetes cluster.

I saved the configuration in a file named kubernutty.yaml, which I’m going to apply to our kubernutty namespace:

kubectl apply -n kubernutty -f kubernutty.yaml
Enter fullscreen mode Exit fullscreen mode

This creates a single pod that runs our container:

NAME                          READY   STATUS    RESTARTS   AGE
kubernutty-57f79c7757-5mmz9   1/1     Running   0          8s
Enter fullscreen mode Exit fullscreen mode

The first thing you probably want to do now, is view the result in a browser. Unfortunately you can’t do that yet. Our configuration doesn’t tell Kubernetes how to do that!

What we can do though, is use kubectl port-forward to forward traffic on our host to the newly created pod:

kubectl port-forward kubernutty-57f79c7757-5mmz9 8080:80 -n kubernutty
Enter fullscreen mode Exit fullscreen mode

We can now access our WordPress installation on http://localhost:8080:
WordPress’s setup screen

What’s next

Hooray, you have committed your first crimes against humanity!

While we could definitely add more cool things, like a domain name or an FTP server, the best thing we can do for now is delete the kubernutty namespace by executing

kubectl delete namespace kubernutty
Enter fullscreen mode Exit fullscreen mode

and not talk about this ever again.

Top comments (0)